開いているxml word docファイルのいくつかの組み込みプロパティ(作成者、最終更新日など)にアクセスしたいと思います。私はこの目的のためにオープンxmlのsdk2.0を使用したいと思います。だから、もし私はこれらの組み込みプロパティにプログラムでアクセスできる任意のクラスや方法があるのだろうかと思います。open xml worddocファイルの組み込みプロパティにプログラムでアクセスする方法
4
A
答えて
8
次の方法の説明はhereを見つけることができますが、かなり多くのあなたは、このメソッドにcore.xmlファイルから取得したいプロパティに渡す必要があり、それが値を返します:
をパワーポイントのような他のオープンXML形式のためにも働くusing System.IO.Packaging.Package;
[...]
using (var package = Package.Open(path))
{
package.PackageProperties.Creator = Environment.UserName;
package.PackageProperties.LastModifiedBy = Environment.UserName;
}
:
public static string WDRetrieveCoreProperty(string docName, string propertyName)
{
// Given a document name and a core property, retrieve the value of the property.
// Note that because this code uses the SelectSingleNode method,
// the search is case sensitive. That is, looking for "Author" is not
// the same as looking for "author".
const string corePropertiesSchema = "http://schemas.openxmlformats.org/package/2006/metadata/core-properties";
const string dcPropertiesSchema = "http://purl.org/dc/elements/1.1/";
const string dcTermsPropertiesSchema = "http://purl.org/dc/terms/";
string propertyValue = string.Empty;
using (WordprocessingDocument wdPackage = WordprocessingDocument.Open(docName, true))
{
// Get the core properties part (core.xml).
CoreFilePropertiesPart corePropertiesPart = wdPackage.CoreFilePropertiesPart;
// Manage namespaces to perform XML XPath queries.
NameTable nt = new NameTable();
XmlNamespaceManager nsManager = new XmlNamespaceManager(nt);
nsManager.AddNamespace("cp", corePropertiesSchema);
nsManager.AddNamespace("dc", dcPropertiesSchema);
nsManager.AddNamespace("dcterms", dcTermsPropertiesSchema);
// Get the properties from the package.
XmlDocument xdoc = new XmlDocument(nt);
// Load the XML in the part into an XmlDocument instance.
xdoc.Load(corePropertiesPart.GetStream());
string searchString = string.Format("//cp:coreProperties/{0}", propertyName);
XmlNode xNode = xdoc.SelectSingleNode(searchString, nsManager);
if (!(xNode == null))
{
propertyValue = xNode.InnerText;
}
}
return propertyValue;
}
+0
ありがとうたくさんのアマチュア。 – stazera
1
関連する問題
- 1. コード内の組み込みプロパティを使用する方法
- 2. eclipse plugin> jarファイルをプログラムに組み込む方法
- 3. xmlの読み込み/プロジェクトへの組み込み - C#
- 4. このコードをC#プログラムに組み込む方法
- 5. Javaでのmp3ファイルの組み込み
- 6. SDWebImageフレームワークの組み込み方法
- 7. NHibernate QueryOverにプロパティ値の変換を組み込む方法.SelectList?
- 8. ユーザーコントロールのプロパティをプログラムで読み込むと、そのユーザーコントロールのプロパティにアクセスする方法は?
- 9. cabファイル内のxmlファイルをプログラムで読み取る方法
- 10. 生のHTMLを解析する組み込みの方法
- 11. PHP読み込みXMLファイル
- 12. Visual C++で128ビットの組み込み組み込み
- 13. unittest後に組み込みのcassandraをクリーンアップする方法は?
- 14. 組み込みの検索ダイアログを無効にする方法
- 15. キュウリに春を組み込む方法
- 16. 組み込みLinuxファイル名の長さ
- 17. サービスエンドポイントアドレスのWCFプログラムによる組み込み
- 18. 組み込みアンダートーでWebSocketを実行する方法は?
- 19. Lessで組み込み関数をエスケープする方法は?
- 20. 組み込みWebサーバにGWTアプリケーションをデプロイする方法
- 21. Pythonで組み込み関数のプロパティ()を使用する方法と使用方法
- 22. プリセットhtmlファイルはプログラムに組み込まれていますか?
- 23. C++の組み込みリソース
- 24. 別のモジュールに組み込みアセンブリを組み込むこと
- 25. XMLでファイルを読み込みJava
- 26. SSMLをPythonに組み込む方法
- 27. 組み込み関数/組み込み関数のテスト
- 28. 私のアプリに組み込みのiOSアラームクロックサウンドにアクセス
- 29. javascriptネイティブオブジェクトの組み込みメソッドを上書きする方法
- 30. 組み込みのファイルコピーダイアログを表示する方法は?
[https://searchcode.com/codesearch/view/10033886/] (https://searchcode.com/codesearch/view/10033886/)のヒントについては、このコードをご覧ください。 – AnorZaken