3
我正在尝试使用以下代码生成新的Word文档。 Word文档在没有settings.xml的情况下生成。我需要在word文件中有settings.xml。任何帮助,将不胜感激。openxml-sdk - 使用settings.xml创建word 2007文件
public static byte[] GenerateNewDocument()
{
byte[] returnValue = null;
MemoryStream stream = null;
WordprocessingDocument wordDoc = null;
try
{
stream = new System.IO.MemoryStream();
wordDoc = WordprocessingDocument.Create(stream, WordprocessingDocumentType.Document);
}
catch
{
if (stream != null)
{
stream.Close();
}
throw;
}
using (wordDoc)
{
wordDoc.AddMainDocumentPart();
MainDocumentPart mainPart = wordDoc.MainDocumentPart;
mainPart.Document = new Document(new Body());
mainPart.Document.Save();
}
returnValue = stream.ToArray();
return returnValue;
}
莫非settings.xml中的内容在一个局部变量中,并且可以使用它? – 2011-05-20 18:54:41
是的,它可以是预制的,例如我上面给出的例子,也可以使用零件的成员动态创建,例如http://msdn.microsoft.com/en-us/library/ documentformat.openxml.packaging.documentsettingspart_members.aspx。 – 2011-05-22 01:08:59
宅男,谢谢。我已经使用了这种方法,并且可行。你能帮我在这个问题以及 - http://stackoverflow.com/questions/5877182/open-xml-using-stylepaneformatfilter-attribute-to-show-normal-style-along-wit – 2011-05-22 04:20:08