Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Wed Sep 22, 2021 6:27 am

Hi,

How do you use Workbook.SaveToStream() method to save an excel stream to .txt format (preferably in UTF8 encoding)?
I tried Workbook.SaveToStream(outStream, " ") but it adds a double quote character at the beginning and end of each row in the output text stream.

Any help appreciated, thanks.

Hailey

bluejet333
 
Posts: 2
Joined: Wed Sep 22, 2021 6:08 am

Wed Sep 22, 2021 8:21 am

Hello Hailey,

Thanks for your inquiry.
I simulated an Excel file and tested the following code, but I did not reproduce your issue. If you are using an older version, we recommend you upgrade to the latest version (the latest version is Spire.XLS Pack(Hotfix) Version:11.9.3) and try it again.
Code: Select all
            Workbook workbook = new Workbook();
            workbook.LoadFromFile("test.xlsx");
            MemoryStream outStream = new MemoryStream();
            workbook.SaveToStream(outStream, " ");
           
            File.WriteAllBytes("result.txt", outStream.ToArray());

If there are still any issues, to help us investigate further, please provide us with your input file and your test code. You can upload them here or send them to us (support@e-iceblue.com) via email. Thanks in advance.

Besides, our Spire.XLS does not support saving a workbook stream to .txt format in UTF8 encoding, but we support saving a worksheet stream to .txt format in UTF8 encoding (As shown below).
Code: Select all
            workbook.Worksheets[0].SaveToStream(outStream, " ",Encoding.UTF8);


Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Thu Sep 23, 2021 4:55 pm

HI Brian,

Thanks for the reply and tips on using Worksheets.SaveToStream for CSV & TXT format instead of Workbook.
The double quotes text qualifiers are still there however but I managed to resolve it by stripping them with str.Replace.

bluejet333
 
Posts: 2
Joined: Wed Sep 22, 2021 6:08 am

Fri Sep 24, 2021 1:15 am

Thanks for your feedback.
If there are any other issues related to our products, just feel free to contact us.

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Return to Spire.XLS