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 Feb 24, 2021 4:44 pm

With Free Spire.XLS is it possible to set the sheet name using LoadFromFile (method)?

I'm converting csv files to xlsx files and some of the filenames are over 31 characters long, and as a sheet name can only have a max of 31 characters I get an error message.

Is there any workaround, other than renaming the file before converting it?

Thanks

sconly
 
Posts: 12
Joined: Wed May 08, 2019 10:11 am

Thu Feb 25, 2021 1:58 am

Hello,

Thanks for your inquiry.
For CSV files with a file name longer than 31 characters, you can load it from stream(as shown below), I have verified that this will not throw errors.
Code: Select all
            FileStream fileStream = new FileStream("your filename.csv", FileMode.Open);
            Workbook wb = new Workbook();
            wb.LoadFromStream(fileStream, ",", 1, 1);
            wb.SaveToFile("result.xlsx");


If there are any questions, please 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

Thu Feb 25, 2021 11:06 am

Brilliant.

Thanks for the help.

One thing I would add is to close the FileStream, so the file doesn't get locked, by adding the following code...

Code: Select all
fileStream.Close();
Last edited by sconly on Fri Feb 26, 2021 10:13 am, edited 1 time in total.

sconly
 
Posts: 12
Joined: Wed May 08, 2019 10:11 am

Fri Feb 26, 2021 5:45 am

You are welcome.
If you encounter any issues related to our products in the future, please 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