标签: openxml-sdk

如何更改字体打开xml

如何通过OpenXml更改文档的字体系列?我尝试了一些方法但是,当我打开文档时,它总是在Calibri中

按照我的代码,我尝试了.

我认为Header Builder无用于发布

private static void BuildDocument(string fileName, List<string> lista, string tipo)
{                
    using (var w = WordprocessingDocument.Create(fileName, WordprocessingDocumentType.Document))
    {
        var mp = w.AddMainDocumentPart();
        var d = new DocumentFormat.OpenXml.Wordprocessing.Document();
        var b = new Body();
        var p = new DocumentFormat.OpenXml.Wordprocessing.Paragraph();
        var r = new Run();

        // Get and format the text.                                    
        for (int i = 0; i < lista.Count; i++)
        {
            Text t = new Text();                    
            t.Text = lista[i];
            if (t.Text == "          ")
            {
                r.Append(new CarriageReturn());
            }
            else
            { …
Run Code Online (Sandbox Code Playgroud)

c# openxml openxml-sdk

21
推荐指数
1
解决办法
3万
查看次数

从excel文件中打开xml

我想在我的项目中实现openXml sdk 2.5.我在这个链接中做了一切

using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;
using System.IO.Packaging;


static void Main(string[] args)
        {

            String fileName = @"C:\OPENXML\BigData.xlsx";
            // Comment one of the following lines to test the method separately.
            ReadExcelFileDOM(fileName);    // DOM
            //ReadExcelFileSAX(fileName);    // SAX
        }

        // The DOM approach.
        // Note that the code below works only for cells that contain numeric values.
        // 
        static void ReadExcelFileDOM(string fileName)
        {
            using (SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Open(fileName, false))
            {
                WorkbookPart workbookPart = spreadsheetDocument.WorkbookPart;
                WorksheetPart worksheetPart = workbookPart.WorksheetParts.First(); …
Run Code Online (Sandbox Code Playgroud)

c# excel openxml-sdk

21
推荐指数
3
解决办法
8万
查看次数

使用OpenXML将%数字格式应用于单元格值

我想使用开放的XML C#应用%(百分比)数字格式

我有数值3.6,我想在Excel中显示该数字为3.6%.

我如何实现这一目标?

c# openxml openxml-sdk

20
推荐指数
4
解决办法
5万
查看次数

将多个word文档合并为一个Open Xml

我有大约10个word文档,我使用open xml和其他东西生成.现在我想创建另一个word文档,我想逐个加入到这个新创建的文档中.我希望使用open xml,任何提示都会很明显.以下是我的代码:

 private void CreateSampleWordDocument()
    {
        //string sourceFile = Path.Combine("D:\\GeneralLetter.dot");
        //string destinationFile = Path.Combine("D:\\New.doc");
        string sourceFile = Path.Combine("D:\\GeneralWelcomeLetter.docx");
        string destinationFile = Path.Combine("D:\\New.docx");
        try
        {
            // Create a copy of the template file and open the copy
            //File.Copy(sourceFile, destinationFile, true);
            using (WordprocessingDocument document = WordprocessingDocument.Open(destinationFile, true))
            {
                // Change the document type to Document
                document.ChangeDocumentType(DocumentFormat.OpenXml.WordprocessingDocumentType.Document);
                //Get the Main Part of the document
                MainDocumentPart mainPart = document.MainDocumentPart;
                mainPart.Document.Save();
            }
        }
        catch
        {
        }
    }
Run Code Online (Sandbox Code Playgroud)

更新(使用AltChunks):

using (WordprocessingDocument myDoc = WordprocessingDocument.Open("D:\\Test.docx", true)) …
Run Code Online (Sandbox Code Playgroud)

c# merge docx openxml openxml-sdk

20
推荐指数
2
解决办法
3万
查看次数

使用Open XML SDK替换Word文件中的书签文本

我认为2.0是更好的... ...他们有一些不错的"如何..." 的例子,但书签似乎并不为明显充当说表...一个书签被定义2个 XML元素BookmarkStart&书签结束.我们有一些带有书签的模板作为书签,我们只想用其他文本替换书签......没有奇怪的格式化,但如何选择/替换书签文字?

c# ms-word openxml openxml-sdk

19
推荐指数
3
解决办法
5万
查看次数

无法在运行之间保留空间

我想生成一个word文档作为输入我有这个字符串"打开包装约定",每个单词将有不同的风格,结果应该是打开包装约定

WordprocessingDocument document = WordprocessingDocument.Create(
            @"C:\test PFE.docx",
            WordprocessingDocumentType.Document
        );



        MainDocumentPart mainDocumentPart = document.AddMainDocumentPart();


        mainDocumentPart.Document = new Document();
        mainDocumentPart.Document.AddNamespaceDeclaration("ve", "http://schemas.openxmlformats.org/markup-compatibility/2006");
        mainDocumentPart.Document.AddNamespaceDeclaration("o", "urn:schemas-microsoft-com:office:office");
        mainDocumentPart.Document.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
        mainDocumentPart.Document.AddNamespaceDeclaration("m", "http://schemas.openxmlformats.org/officeDocument/2006/math");
        mainDocumentPart.Document.AddNamespaceDeclaration("v", "urn:schemas-microsoft-com:vml");
        mainDocumentPart.Document.AddNamespaceDeclaration("wp", "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing");
        mainDocumentPart.Document.AddNamespaceDeclaration("w10", "urn:schemas-microsoft-com:office:word");
        mainDocumentPart.Document.AddNamespaceDeclaration("w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main");
        mainDocumentPart.Document.AddNamespaceDeclaration("wne", "http://schemas.microsoft.com/office/word/2006/wordml");



        Body documentBody = new Body();
        mainDocumentPart.Document.Append(documentBody);


        StyleDefinitionsPart styleDefinitionsPart =
        mainDocumentPart.AddNewPart<StyleDefinitionsPart>();


        FileStream stylesTemplate =
            new FileStream("styles.xml", FileMode.Open, FileAccess.Read);
        styleDefinitionsPart.FeedData(stylesTemplate);
        styleDefinitionsPart.Styles.Save();



        #region Titre du document


        Paragraph titleParagraphe = new Paragraph() { RsidParagraphAddition = "00AF4948", RsidParagraphProperties = "00625634", RsidRunAdditionDefault = "00625634" }; ;

        Run run …
Run Code Online (Sandbox Code Playgroud)

space openxml-sdk wordprocessingml

19
推荐指数
2
解决办法
8490
查看次数

将HTML字符串添加到OpenXML(*.docx)文档

我正在尝试使用Microsoft的OpenXML 2.5库来创建OpenXML文档.一切都很好,直到我尝试在我的文档中插入HTML字符串.我已经浏览了网页,这是我到目前为止所提出的内容(剪切到我遇到问题的部分):

Paragraph paragraph = new Paragraph();
Run run = new Run();

string altChunkId = "id1";
AlternativeFormatImportPart chunk =
       document.MainDocumentPart.AddAlternativeFormatImportPart(
           AlternativeFormatImportPartType.Html, altChunkId);
chunk.FeedData(new MemoryStream(Encoding.UTF8.GetBytes(ioi.Text)));
AltChunk altChunk = new AltChunk { Id = altChunkId };

run.AppendChild(new Break());

paragraph.AppendChild(run);
body.AppendChild(paragraph);
Run Code Online (Sandbox Code Playgroud)

显然,我在这个例子中并没有实际添加altChunk,但我尝试将它附加到任何地方 - 运行,段落,正文等.在任何情况下,我都无法打开Word 2010中的docx文件.

这让我有点疯狂,因为它看起来应该是直截了当的(我承认我并没有完全理解AltChunk"的事情").非常感谢任何帮助.

旁注:我发现有一件事很有意思,我不知道它是否真的是一个问题,这个响应表明AltChunk在使用MemoryStream工作时会破坏文件.任何人都能证实这是/不是真的吗?

c# openxml openxml-sdk

19
推荐指数
1
解决办法
2万
查看次数

如何在Open XML工作表中插入日期?

我正在使用Microsoft Open XML SDK 2,我很难在单元格中插入日期.我可以通过设置插入数字而没有问题Cell.DataType = CellValues.Number,但是当我对日期(Cell.DataType = CellValues.Date)执行相同操作时Excel 2010崩溃(2007年也是如此).

我尝试将Cell.Text值设置为多种日期格式以及Excel的日期/数字格式无济于事.我也尝试使用样式,删除type属性,以及我扔在墙上的许多其他比萨...

有人能指出我在工作表中插入日期的例子吗?

c# excel openxml openxml-sdk

18
推荐指数
4
解决办法
2万
查看次数

简化/清理DOCX word文档的XML

我有一个Microsoft Word文档(docx),我使用Open XML SDK 2.0 Productivity Tool从中生成C#代码.

我想以编程方式将一些数据库值插入到文档中.为此我输入了简单的文本,如[[place holder 1]],我的程序应该用它的数据库值替换占位符.

不幸的是,XML输出处于某种混乱状态.例如,我有一个包含两个相邻单元格的表格,这些单元格不应与其占位符区分开来.但其中一个占位符分为几个版本.

[[好地方持有人]]

<w:tc xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
  <w:tcPr>
    <w:tcW w:w="1798" w:type="dxa" />
    <w:shd w:val="clear" w:color="auto" w:fill="auto" />
  </w:tcPr>
  <w:p w:rsidRPr="008C2E16" w:rsidR="001F54BF" w:rsidP="000D7B67" w:rsidRDefault="0009453E">
    <w:pPr>
      <w:spacing w:after="0" w:line="240" w:lineRule="auto" />
      <w:rPr>
        <w:rFonts w:cstheme="minorHAnsi" />
        <w:sz w:val="20" />
        <w:szCs w:val="20" />
      </w:rPr>
    </w:pPr>
    <w:r w:rsidRPr="0009453E">
      <w:rPr>
        <w:rFonts w:cstheme="minorHAnsi" />
        <w:sz w:val="20" />
        <w:szCs w:val="20" />
      </w:rPr>
      <w:t>[[good place holder]]</w:t>
    </w:r>
  </w:p>
</w:tc>
Run Code Online (Sandbox Code Playgroud)

[[坏地方持有人]]

<w:tc xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
  <w:tcPr>
    <w:tcW w:w="1799" w:type="dxa" /> …
Run Code Online (Sandbox Code Playgroud)

c# xml ms-word openxml openxml-sdk

18
推荐指数
1
解决办法
1万
查看次数

如何使用OpenXML创建Excel文件而不创建本地文件?

是否可以使用OpenXML SDK创建和编辑Excel文档而无需创建本地文件?

根据文档,该Create方法需要a filepath,它创建文件的本地副本.

SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Create(filepath, SpreadsheetDocumentType.Workbook);
Run Code Online (Sandbox Code Playgroud)

我在这里引用MSDN文章:https: //msdn.microsoft.com/en-us/library/office/ff478153.aspx

我的要求是创建文件,浏览器应该点击按钮下载.

有什么建议吗?

c# excel openxml openxml-sdk

17
推荐指数
1
解决办法
2万
查看次数

标签 统计

openxml-sdk ×10

c# ×9

openxml ×8

excel ×3

ms-word ×2

docx ×1

merge ×1

space ×1

wordprocessingml ×1

xml ×1