使用 DSOFile.OleDocumentPropertiesClass 获取 Office(excel) 文档的页数时出现问题
我正在使用 DSOFile.OleDocumentPropertiesClass 来获取 Office 文档的页数,而无需自动化。这对于 docx 和 pptx 文件效果很好,但对于 xlsx 文件总是返回 0。
DSOFile.OleDocumentPropertiesClass oleDocument = new DSOFile.OleDocumentPropertiesClass();
oleDocument.Open(documentFilePath, true, DSOFile.dsoFileOpenOptions.dsoOptionOpenReadOnlyIfNoWriteAccess);
//WORKS FOR DOCX
int pageCount = oleDocument.SummaryProperties.PageCount;
//WORKS FOR PPTS
int pageCount = oleDocument.SummaryProperties.SheetCount;
//NONE OF ABOVE WORKS FOR XLSX, IT ALWAYS RETURNS 0
I am using DSOFile.OleDocumentPropertiesClass for getting the page count for office documents without automation. This works fine for docx and pptx files but returns always 0 for xlsx files.
DSOFile.OleDocumentPropertiesClass oleDocument = new DSOFile.OleDocumentPropertiesClass();
oleDocument.Open(documentFilePath, true, DSOFile.dsoFileOpenOptions.dsoOptionOpenReadOnlyIfNoWriteAccess);
//WORKS FOR DOCX
int pageCount = oleDocument.SummaryProperties.PageCount;
//WORKS FOR PPTS
int pageCount = oleDocument.SummaryProperties.SheetCount;
//NONE OF ABOVE WORKS FOR XLSX, IT ALWAYS RETURNS 0
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,DSOFile 也不适合我,作为替代方案,您可以使用 OleDB 连接到 xls(x) 文件并获取其内容详细信息。下面是一个示例:
只需确保安装了 Office 2007 系统驱动程序(Microsoft.ACE.OLEDB.12.0 oledb 提供程序),
如果您仅处理 Excel 2007 电子表格,则可以考虑使用 ExcelPackage (http://excelpackage.codeplex .com/)工具,它应该能够从 Excel 电子表格中读取数据,而无需自动化
well, DSOFile doesn't work for me either, as an alternative you can use OleDB to connect to an xls(x) file and get its content details. Below is an example:
just make sure you have the Office 2007 system driver (Microsoft.ACE.OLEDB.12.0 oledb provider) installed
if you're dealing only with Excel 2007 spreadsheets you can consider using ExcelPackage (http://excelpackage.codeplex.com/) tool, it should be able to read data from the excel spreadsheet without automation
我对 excel 文件使用了自动化,对其他格式的 dso 文件使用了自动化,
因为我无法找到任何有关它的解决方案。
I have used automation for excel files and dso file for other formats,
As i can't fild any solution regarding it.