Version 2.9


#1

I moved from V2.8.2 to V2.9 and I get the following error now

Errors in Excel Save method

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Exception: Errors in Excel Save method

Source Error:

Line 57: } Line 58: else Line 59: myExcel.Save(sFileName); Line 60: } Line 61: 

#2

Bit more info

Stack Trace:

[Exception: Errors in Excel Save method] Aspose.Excel.Worksheets.a(UInt32 A_0, Exception A_1) +289 Aspose.Excel.Worksheets.a(String A_0, SaveType A_1, FileFormatType A_2, HttpResponse A_3) +349 [Exception: Errors in Excel Save method] Aspose.Excel.Worksheets.a(UInt32 A_0, Exception A_1) +289 Aspose.Excel.Worksheets.a(String A_0, SaveType A_1, FileFormatType A_2, HttpResponse A_3) +1267 Aspose.Excel.Excel.Save(String fileName, FileFormatType fileFormatType) +342 Aspose.Excel.Excel.Save(String fileName) +7 ACL.Utils.Export.ExportToExcel(DataTable dtData, String sFileName, String sWorkSheetName, Boolean bOpenInExcel) in D:\Projects\SourceCode\Utils\Export.cs:59 ESense.Maintain.Form_Manager.ExportExcel() in d:\projects\esense\maintain\form_manager.aspx.cs:163 ESense.Maintain.Form_Manager.btnExport_Click(Object sender, EventArgs e) in d:\projects\esense\maintain\form_manager.aspx.cs:243 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33 System.Web.UI.Page.ProcessRequestMain() +1273 

#3

Please send me your template and sample code. Thank you.


#4

Not using a template but heres the code I am using

public void ExportToExcel(DataTable dtData, string sFileName, string sWorkSheetName, bool bOpenInExcel)

{

Aspose.Excel.Excel myExcel = new Aspose.Excel.Excel();

Aspose.Excel.Worksheet myWorkSheet = myExcel.Worksheets[0];

myWorkSheet.Name = sWorkSheetName;

Aspose.Excel.Cells myCells = myWorkSheet.Cells;

myCells.ImportDataTable(dtData, this.ShowFieldNames, 0 ,0, dtData.Rows.Count, dtData.Columns.Count, false, “mm/dd/yyyy”);

if(bOpenInExcel)

{

int iLoc = sFileName.LastIndexOf(@"");

sFileName = sFileName.Substring(iLoc + 1);

myExcel.Save(sFileName, Aspose.Excel.SaveType.OpenInExcel, Aspose.Excel.FileFormatType.Default, System.Web.HttpContext.Current.Response);

}

else

myExcel.Save(sFileName);

}

And heres the call to the method

myExport.ExportToExcel(dsExcel.Tables[0], @“d:\maintain\docs” + sFileName, “Form Manager”, false);


#5

I tried your code and found the same error. It’s caused by missing the path “d:\maintain\docs”. Have you already created it in your machine?

And please try to use the following code to see if it works fine:

myExport.ExportToExcel(dsExcel.Tables[0], sFileName, “Form Manager”, true);

Since your program is a web application, please check if your code has the right to access local directory.


#6

Has the way permissions changed recently? I got the file to create but when it run again it doesnt overwrite the old file.


#7

No, I haven’t change the permissions. The permissions depend on your settings. Do you mean that your program creates the file on disk successfully the first time but fails to overwrite the old file when running again?


#8

Exactly. How do I allow the overwrite to occur?


#9

It looks like that your web application didn’t release the file resource. I made some change in Aspose.Excel to avoid this. Please try this attached v2.9.2.1.


#10

Works great now!

Thanks for the quick fix and great support as always.