我正在尋找使用openxml作爲服務器端字自動化項目的替代方案。有沒有人知道任何其他方式有功能,讓我操縱字書籤和表?服務器端字自動化
服務器端字自動化
回答
我目前正在爲我公司開發一個字自動化項目的項目,我正在使用DocX非常簡單直接的API來處理。我使用的方法是,無論何時我需要直接使用XML,此API在Paragraph類中都有一個名爲「xml」的屬性,使您可以訪問基礎xml direclty,以便我可以使用它。最好的部分是它不會破壞XML並且不會破壞最終的文檔。希望這可以幫助!使用DOCX
示例代碼..
XNamespace ns = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
using(DocX doc = DocX.Load(@"c:\temp\yourdoc.docx"))
{
foreach(Paragraph para in doc.Paragraphs)
{
if(para.Xml.ToString().Contains("w:Bookmark"))
{
if(para.Xml.Element(ns + "BookmarkStart").Attribute("Name").Value == "yourbookmarkname")
{
// you got to your bookmark, if you want to change the text..then
para.Xml.Elements(ns + "t").FirstOrDefault().SetValue("Text to replace..");
}
}
}
}
替代API只與書籤的工作是... http://simpleooxml.codeplex.com/
如何刪除bookmarkstart文本使用這個API bookmarkend例..
MemoryStream stream = DocumentReader.Copy(string.Format("{0}\\template.docx", TestContext.TestDeploymentDir));
WordprocessingDocument doc = WordprocessingDocument.Open(stream, true);
MainDocumentPart mainPart = doc.MainDocumentPart;
DocumentWriter writer = new DocumentWriter(mainPart);
//Simply Clears all text between bookmarkstart and end
writer.PasteText("", "YourBookMarkName");
//Save to the memory stream, and then to a file
writer.Save();
DocumentWriter.StreamToFile(string.Format("{0}\\templatetest.docx", GetOutputFolder()), stream);
將word文檔從內存流中加載到不同的API中。
//Loading a document file into memorystream using SimpleOOXML API
MemoryStream stream = DocumentReader.Copy(@"c\template.docx");
//Opening it from the memory stream as OpenXML document
WordprocessingDocument doc = WordprocessingDocument.Open(stream, true);
//Opening it as DocX document for working with DocX Api
DocX document = DocX.Load(stream);
我能使用docX訪問word doc中的書籤嗎? – 2012-03-22 13:31:59
不是開箱即用......但你可以直接從底層XML獲得它..取決於你的要求.. – Flowerking 2012-03-22 13:40:10
你可以舉一個例子,我可以如何使用XML來獲取書籤 – 2012-03-22 13:48:56
- 1. 服務器端的Excel-DNA自動化
- 2. 服務器上的字自動化
- 3. 自動完成服務器端實現
- 4. 流星自動完成服務器端
- 5. 服務器端自動縮小?
- 6. 自動定位客戶端服務器
- 7. Datatables服務器端自動行ID
- 8. 自動生成報告,服務器端
- 9. ASP.NET服務器端文化
- 10. Word自動化服務器端不能正常工作
- 11. 替代的Visio服務器端自動化
- 12. OLE自動化:IDispatch實現類;客戶端或服務器?
- 13. 未安裝自動化服務器
- 14. 服務器上的SSH自動化
- 15. 從現有API自動生成服務器端WCF服務
- 16. Twitter服務自動化
- 17. 服務自動化安裝
- 18. Powershell自動化服務
- 19. 服務器端JavaScript動作
- 20. 如何從遠程服務器訪問Sharepoint 2010字自動化服務?
- 21. 服務器端模板,客戶端模板 - 自動轉換?
- 22. RPC C++服務器端動態端點
- 23. 服務器端渲染/模板化
- 24. R:變化端口與SFTP服務器
- 25. 反序列化json服務器端
- 26. GWT國際化(i18n)在服務器端
- 27. 客戶端服務器應用程序:從本地服務器或版本化界面自動更新?
- 28. 如何自動啓動服務器端應用程序?
- 29. 自定義CSLA服務器端初始化
- 30. 自動化:從服務器列表中找到未使用的服務器
你在試圖自動化什麼,爲什麼openxml不適合你的需求,沒有這些細節,將很難提供其他選項。 – 2012-03-22 14:17:40
我正試圖刪除書籤開始和bookmarkend內的所有文本。就我所知,openxml不允許我這樣做 – 2012-03-22 14:22:23
現在知道你想要做什麼看到這個問題,它基本上是你想要做的同樣的事情。 http://stackoverflow.com/questions/3308299/replace-bookmark-text-in-word-file-using-open-xml-sdk – 2012-03-22 14:34:00