如何通过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) 我想在我的项目中实现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) 我想使用开放的XML C#应用%(百分比)数字格式
我有数值3.6,我想在Excel中显示该数字为3.6%.
我如何实现这一目标?
我有大约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) 我认为2.0是更好的... ...他们有一些不错的"如何..." 的例子,但书签似乎并不为明显充当说表...一个书签被定义2个 XML元素BookmarkStart&书签结束.我们有一些带有书签的模板作为书签,我们只想用其他文本替换书签......没有奇怪的格式化,但如何选择/替换书签文字?
我想生成一个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) 我正在尝试使用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工作时会破坏文件.任何人都能证实这是/不是真的吗?
我正在使用Microsoft Open XML SDK 2,我很难在单元格中插入日期.我可以通过设置插入数字而没有问题Cell.DataType = CellValues.Number,但是当我对日期(Cell.DataType = CellValues.Date)执行相同操作时Excel 2010崩溃(2007年也是如此).
我尝试将Cell.Text值设置为多种日期格式以及Excel的日期/数字格式无济于事.我也尝试使用样式,删除type属性,以及我扔在墙上的许多其他比萨...
有人能指出我在工作表中插入日期的例子吗?
我有一个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) 是否可以使用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
我的要求是创建文件,浏览器应该点击按钮下载.
有什么建议吗?