Spire.Doc Read documents that are not doc extensions

Technical support for Spire.Doc

Moderator: iceblue support

Spire.Doc Read documents that are not doc extensions

Postby sfddv11 » Wed Aug 09, 2017 11:31 am

Problem description:
I have a document that is in word format, and the document extension is non doc/docx. I need to read the contents of the document through Spire.Doc.
My current solution is to change the extension of the document to Doc, and then read the contents of the operation, after the completion of the operation, and then expand the document back to non doc/docx.
But the performance of such a program is not good enough. Is there any other solution?
The original solution code is as follows:
问题描述:
我有一个文档,该文档为word格式,文档的拓展名为非doc/docx。我需要通过Spire.Doc读取文档的内容。
我目前的解决方案是将文档的拓展名改为doc,然后进行内容读取操作,操作完成后再将文档的拓展改回非doc/docx。
但是这样的方案运行性能不够好,有没有其它的解决方案呢?
原解决方案代码如下:
//修改文件拓展名为doc
//Modify the file extension to doc
string ext_old = "";
ext_old = Path.GetExtension(path_old);
string path_new = Path.ChangeExtension(path_old, ".doc");
File.Move(path_old, path_new);

//读取修改拓展名后的文件
//Read and modify the extension after the file
Document doc = new Document();
doc.LoadFromFile(path_new);

//修改文件拓展名非doc
//Modify file extensions to non doc
File.Move(path_new, path_old);
sfddv11
 
Posts: 3
Joined: Tue Jun 13, 2017 9:23 am

Re: Spire.Doc Read documents that are not doc extensions

Postby Jane.Bai » Thu Aug 10, 2017 2:08 am

Hello,

Thanks for your inquiry.
Our Spire.Doc supports loading the file of Word format. If possible, could you please tell us what indeed the file extension is? And it would be better if you could share the file with us.

你好,
感谢你的咨询。
我们的Spire.Doc组件是支持加载Word格式的文件的。 方便的话,能够告诉我们文件扩展名具体是什么吗? 当然,如果你能提供这个文档的话那就更好了。
对了,我们公司是在中国,提供中文技术支持服务,所以你可以直接用中文回复。

Sincerely,
Jane
E-iceblue support team
User avatar
Jane.Bai
 
Posts: 263
Joined: Tue Nov 29, 2016 1:47 am

Re: Spire.Doc Read documents that are not doc extensions

Postby sfddv11 » Thu Aug 10, 2017 2:59 pm

非常感谢您的回复,我以上传样本文件。

运行代码:
Code: Select all
            Document doc = new Document();
            doc.LoadFromFile(@"D:\PWGJJKL01.101");


报错信息:Cannot detect current file type
You do not have the required permissions to view the files attached to this post.
sfddv11
 
Posts: 3
Joined: Tue Jun 13, 2017 9:23 am

Re: Spire.Doc Read documents that are not doc extensions

Postby Jane.Bai » Fri Aug 11, 2017 2:54 am

感谢你的回复,

只要保证文件的本质是个word文档, 你就可以直接用流加载而不需要去改后缀了。
下面是我这边的测试代码。
Code: Select all
Document doc = new Document();
            Stream stream = File.OpenRead(@"C:\Users\Administrator\Desktop\PWGJJKL01\PWGJJKL01.101");
            doc.LoadFromStream(stream,FileFormat.Doc);         
            doc.SaveToFile("101.docx", FileFormat.Docx2013);


Sincerely,
Jane
E-iceblue support team
User avatar
Jane.Bai
 
Posts: 263
Joined: Tue Nov 29, 2016 1:47 am

Re: Spire.Doc Read documents that are not doc extensions

Postby sfddv11 » Fri Aug 11, 2017 3:05 am

非常感谢,成功的解决了问题,我之前也采用这种方式,但是我doc.LoadFromStream(stream, FileFormat.Doc);这里没有选择正确的格式。再次感谢帮助。
sfddv11
 
Posts: 3
Joined: Tue Jun 13, 2017 9:23 am

Re: Spire.Doc Read documents that are not doc extensions

Postby Jane.Bai » Fri Aug 11, 2017 3:18 am

很高兴帮助你解决了问题。
如果还有什么其他问题的话,欢迎联系我们。

Sincerely,
Jane
E-iceblue support team
User avatar
Jane.Bai
 
Posts: 263
Joined: Tue Nov 29, 2016 1:47 am


Return to Spire.Doc

Who is online

Users browsing this forum: No registered users and 1 guest