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 Oct 25, 2023 9:34 am

Hi Spire,

I am separating an excel file with three sheets into three different excel file with one sheet of content each.
I found that the file size after removing the irrelevant sheets is not reducing much compare to the original excel file.
Do you have any idea on this?
Or is there any other option to separate those sheets?

Thanks in advanced.

Code: Select all
                    for (int a = 0; a < wsConvert.ToInt32(totalSheetCount); a++)
                    {
                        workbook.LoadFromFile(oriFilePath);
                        for (int snum = workbook.Worksheets.Count - 1; snum >= 0; snum--)
                        {
                            if (snum != a)
                            {
                                workbook.Worksheets[snum].Remove();
                            }
                        }
                        string fullpath = savepath + Path.DirectorySeparatorChar + "sheet_" + a + ".xlsx";
                        workbook.SaveToFile(fullpath, ExcelVersion.Version2016);
                    }
Attachments
file size.png
file size.png (14.28 KiB) Viewed 2020 times

mshyan_spire
 
Posts: 15
Joined: Tue Jul 12, 2022 2:50 am

Thu Oct 26, 2023 2:25 am

Hi,

Thank you for bringing the issue to our attention. I have simulated an XLSX document with two worksheets and used the following code to perform worksheet copying. However, I noticed a change in the file size of the document.
Code: Select all
Workbook wb = new Workbook();
wb.LoadFromFile(@"test.xlsx");

Workbook wb1 = new Workbook();
Workbook wb2 = new Workbook();

wb1.CopyTheme(wb);
wb2.CopyTheme(wb);

wb1.Worksheets[0].CopyFrom(wb.Worksheets[0]);
wb2.Worksheets[0].CopyFrom(wb.Worksheets[1]);

wb1.SaveToFile("test1.xlsx");
wb2.SaveToFile("test2.xlsx");


result.png
result.png (6.99 KiB) Viewed 2010 times


I suggest using the code I provided to perform worksheet copying and test if the problem persists. If the issue still exists, I kindly request you to provide us with your testing document. You can share it with us via email([email protected]) or attach it here. Thanks for your assistance.

Look forward to hearing from you.

Best regards,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Thu Oct 26, 2023 8:30 am

Thank you Triste, I able to solve using the code you provided.

mshyan_spire
 
Posts: 15
Joined: Tue Jul 12, 2022 2:50 am

Thu Oct 26, 2023 9:00 am

Hi,

Thanks for your reply.

Glad to hear that you have solved this issue. If you have any other questions, just feel free to contact us. We are here to help you.

Have a nice day!

Best regards,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Return to Spire.XLS