![](/img/trans.png)
[英]how can i open .pdf file in office word 2013(in c#) and save as it in .docx (code in c#)?
[英]How can I save as word.docx in open xml
我需要打開一個模板,添加一些文本,然后使用新名稱保存它。 如何用新名稱保存?
String Dir = @"F:\template.docx";
WordprocessingDocument wordprocessingDocument = WordprocessingDocument.Open(Dir, true);
Body body = wordprocessingDocument.MainDocumentPart.Document.Body;
Paragraph paragraph1 = body.AppendChild(new Paragraph());
Run run1 = new Run();
RunProperties runProperties1 = new RunProperties();
Bold bold2 = new Bold();
FontSize fontSize2 = new FontSize() { Val = "28" };
runProperties1.Append(bold2);
runProperties1.Append(fontSize2);
Text text1 = new Text();
text1.Text = "text";
run1.Append(runProperties1);
run1.Append(text1);
paragraph1.Append(Hearder1);
paragraph1.Append(run1);
wordprocessingDocument.Close();
byte[] byteArray = File.ReadAllBytes("D:\Document.docx");
using (var stream = new MemoryStream())
{
stream.Write(byteArray, 0, (int)byteArray.Length);
using (var document = WordprocessingDocument.Open(stream, true))
{
//Here fill document
}
// And save file
File.WriteAllBytes("D:\NewDocument.docx", stream.ToArray());
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.