我想生成一个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) 我正在使用以下代码创建Word格式.doc,然后使用cfheader和cfcontent来提供服务.一切都很好,但我需要能够在页眉(或页脚)中放置动态信息,否则自动页面编号将是第二个最佳选择.
我该如何修改代码?
<cfsavecontent variable="myDocument">
<html xmlns:w="urn:schemas-microsoft-com:office:word">
<!--- Head tag instructs Word to start up a certain way, specifically in
print view. --->
<head>
<xml>
<w:WordDocument>
<w:View>Print</w:View>
<w:SpellingState>Clean</w:SpellingState>
<w:GrammarState>Clean</w:GrammarState>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
</w:Compatibility>
<w:DoNotOptimizeForBrowser/>
</w:WordDocument>
</xml>
</head>
<body>
Regular HTML document goes here
<!--- Create a page break microsoft style (took hours to find this)
--->
<br clear="all"
style="page-break-before:always;mso-break-type:page-break" />
Next page goes here
</body>
</html>
</cfsavecontent>
Run Code Online (Sandbox Code Playgroud) 如何从docx文件中逐字(带样式)阅读.我想逐个比较两个docx文件,并根据我要写入另一个docx文件的差异(使用c#和OOXML).我尝试使用DocumentFormat.OpenXml.Extensions.dll,OpenXMLdiff.dll和ICSharpCode.SharpZipLib.dll来实现这一点,但没有任何东西可以让我逐字阅读(ICSharpCode.SharpZipLib确实逐字逐句地提供)它不会给出与该词相关的风格).
任何有关这方面的帮助都非常有用.
如何使用OpenXML获取嵌入在Word文档中的CheckBox控件的句柄?
您会认为Paragraph.ControlPropertiesPart或Paragraph.Descendents()会实现某些功能,但在每种情况下我都会返回null类型.
我可以使用实际的XML结构遍历文档树,但这似乎很麻烦.
建议欢迎.
你知道什么基本信息必须<w:p/>
在*.docx文档中的document.xml中包含一个段落(),它指定一个图像吗?我知道必须有:
<a:blip r:embed="rId4" />
Run Code Online (Sandbox Code Playgroud)
指定关系id,但还有什么?很难在Google中找到它并尝试从现成文档中删除标签或阅读规范需要花费大量时间.
将非常感谢所有必需标签的示例.
我想将Word 2007或更高版本的docx文件上传到我的Web服务器,并将目录转换为简单的xml结构.使用传统VBA在桌面上执行此操作似乎很容易.查看用于创建docx文件的WordprocessingML XML数据令人困惑.有没有一种方法(没有COM)以更加面向对象的方式导航文档?
我正在使用一个模板文档,该模板使用CustomXmlBlocks作为占位符来放置表和其他信息。我需要能够以某种方式将图像放入这些块之一中,即使将其首先放入运行中也是如此。
图像以字节数组(最终为.bmp格式)从数据库的数据集中返回。
我试图做这样的事情,只是为了查看是否可以将图像显示在文档中,但无济于事:
ImagePart imagePart = mainPart.AddImagePart(ImagePartType.Bmp);
MemoryStream imageStream = new MemoryStream(imgData); //imgData is the byte array
imagePart.FeedData(imageStream);
Run Code Online (Sandbox Code Playgroud)
我一直认为必须有一种简单的方法来获取字节流并将其放入文档中,但是我一直无法在任何地方找到任何示例。我现在是否需要对该imagePart做其他事情?
我想要的是:我正在编辑一个WordprocessingDocument
,并在其中添加一些跟踪的更改.这部分完成了.现在,我希望MS word 默认显示所有修订版,即,它不应要求用户单击红色侧栏以打开文档中的跟踪更改.
我做了什么:对于这一点,我发现了一类RevisionView
,它增加了XML元素<w:revisionView />
的settings.xml
下w:settings
元素.该RevisionView
有一个像一些属性Comments
,DisplayRevision
,Formatting
等我明确它们都设置为true
.
RevisionView revView = new RevisionView();
revView.DisplayRevision = new OnOffValue(true);
revView.Formatting = new OnOffValue(true);
revView.InkAnnotations = new OnOffValue(true);
revView.Markup = new OnOffValue(true);
revView.Comments = new OnOffValue(true);
Run Code Online (Sandbox Code Playgroud)
然后我把它添加revView
到Settings
:
Settings settings = wordprocessingDocument.MainDocumentPart.DocumentSettingsPart.Settings;
settings.RemoveAllChildren<RevisionView>();
settings.AppendChild(revView);
settings.Save();
Run Code Online (Sandbox Code Playgroud)
然后我明确地检查了文档xml,它在以下内容中添加了以下xml settings
:
<w:revisionView w:markup="true" w:comments="true" w:insDel="true" w:formatting="true" w:inkAnnotations="true" />
Run Code Online (Sandbox Code Playgroud)
但是在设置中添加此元素不会影响视图.它没有显示默认打开的修订版.
然后,出于测试目的,我将手中的zoom …
我正在尝试使用 OpenXML 和 Eric White 的 OpenXmlPowerTools(从 NuGet 安装)对 .docx Word 文档上的文本进行基本搜索和替换。我已经遵循了该网站和他的博客上的示例,但由于某种原因,当我在运行代码后打开文档时,我从未看到文档中出现的更改。这是我正在运行的简单函数:
void ReadDocument(string path)
{
using (WordprocessingDocument doc = WordprocessingDocument.Open(path, true))
{
var content = doc.MainDocumentPart.GetXDocument().Descendants(W.p);
var regex = new Regex(@"the", RegexOptions.IgnoreCase);
int count = OpenXmlRegex.Replace(content, regex, "NewText", null);
doc.MainDocumentPart.Document.Save();
doc.Save();
MessageBox.Show(count.ToString());
}
}
Run Code Online (Sandbox Code Playgroud)
消息框确实显示了它应该进行的大量替换,但是当我打开文档时,我没有看到任何替换。另外,我认为我不需要这些文档 .Save() 调用,但我一直在尝试任何方法来让这个东西工作。有什么建议么?谢谢
我正在使用DocumentFormat.OpenXml.Wordprocessing
在 Word 文档中添加表格。我需要的是删除表格最后 3(/N) 行中前 4(/6) 个单元格的边框。这些行的添加方式如下:
t.Append(new TableRow(
new TableCell(new Paragraph(new Run(new Text()))),
new TableCell(new Paragraph(new Run(new Text()))),
new TableCell(new Paragraph(new Run(new Text()))),
new TableCell(new Paragraph(new Run(new Text()))),
new TableCell(new Paragraph(new Run(new Text("Total:")))),
new TableCell(new Paragraph(new Run(new Text(priceTotal.ToString()))))
));
Run Code Online (Sandbox Code Playgroud)
我该如何设置TableCellBorders
?我尝试过一些事情,例如:
TableCell cell = new TableCell();
cell.TableCellProperties.TableCellBorders.LeftBorder.Size.Value = 0;
cell.TableCellProperties.TableCellBorders.RightBorder.Size.Value = 0;
cell.TableCellProperties.TableCellBorders.TopBorder.Size.Value = 0;
cell.TableCellProperties.TableCellBorders.BottomBorder.Size.Value = 0;
Run Code Online (Sandbox Code Playgroud)
然而,我尝试过的一切都会回归System.NullReferenceException
。删除单元格边框的正确方法是什么?
wordprocessingml ×10
openxml ×8
openxml-sdk ×5
c# ×4
docx ×2
asp.net ×1
c#-3.0 ×1
coldfusion ×1
drawingml ×1
ms-word ×1
office-2010 ×1
space ×1
wordml ×1