[英]Convert xml file to .doc or .ppt
我有一些 xml 文件,我必須使用格式將其動態轉換為 doc 文件。 什么是最好的方法? xml是以下類型
What does that mean?</RichText><RichText><Emph>MIKE</Emph>
Look at this... (<Italic>he points, triumphantly</Italic>) Rust.</RichText><RichText><Emph>MRS. MENDEZ</Emph> (<Italic>looking</Italic>)
Looks like dirt to me.</RichText><RichText><Emph>MIKE </Emph>(<Italic>nose in computer, tapping</Italic>)
應該有多種方法可以創建格式化的 MS Office 文檔。 可能最好的選擇是使用Open XML SDK 。
這是一個很好的代碼示例在這里
// To add a new document part to a package.
public static void AddNewPart(string document, string fileName)
{
using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(document, true))
{
MainDocumentPart mainPart = wordDoc.MainDocumentPart;
CustomXmlPart myXmlPart = mainPart.AddCustomXmlPart(CustomXmlPartType.CustomXml);
using (FileStream stream = new FileStream(fileName, FileMode.Open))
{
myXmlPart.FeedData(stream);
}
}
}
PS 您也可以嘗試使用 XSLT 轉換、MS Office Interop 等。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spire.Doc;
namespace Xml2Pdf
{
class Program
{
static void Main(string[] args)
{
Document doc = new Document();
doc.LoadFromFile("sample.xml", FileFormat.Xml);
doc.SaveToFile("test.doc", FileFormat.Doc);
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.