Spire.XLS for .NET is a professional Excel .NET library that can be used to any type of .NET( C#, VB.NET, ASP.NET, .NET Core) application, both ASP.NET web sites and Windows Forms application.

Mon Aug 06, 2018 9:47 am

I have created a worksheet dynamically and then try to delete it at the end but when I delete the worksheet and try to save the workbook , a Null Pointer Exception is thrown . Please help me out . Thank you

Sample Code :-

Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
worksheet.Name = "Sheet 7777";
worksheet.Range["A3"].Text = "Hello World";
workbook.SaveToFile("NEw File.xlsx", ExcelVersion.Version2016);
Worksheet sheet = workbook.Worksheets[1];
sheet.Name = "Hello";
workbook.SaveToFile("NEw File.xlsx", ExcelVersion.Version2016);
workbook.Worksheets.Remove("Sheet 7777"); // tried both , same exception is thrown
//workbook.Worksheets[0].Remove();
workbook.SaveToFile("NEw File.xlsx", ExcelVersion.Version2016);

akhil007
 
Posts: 2
Joined: Mon Aug 06, 2018 9:40 am

Mon Aug 06, 2018 10:28 am

Hello Akhil,

Thanks for your inquiry.
Please add below code to load the xlsx file before removing a worksheet. If you have other questions, please do not hesitate to contact us.
Code: Select all
workbook.LoadFromFile("NEw File.xlsx");


Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 949
Joined: Wed Apr 25, 2018 3:20 am

Wed Aug 22, 2018 6:50 am

Hello Akhil,

Greetings from E-iceblue.
Did my code help you? Your feedback will be greatly appreciated.

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 949
Joined: Wed Apr 25, 2018 3:20 am

Return to Spire.XLS