We recently upgraded to a newer version of Aspose.Total for .Net. In rebuilding an older Aspose.Cells app I'm receiving the following errors:
WorkbookDesigner wbd = new WorkbookDesigner();
wbd.Open(page.Server.MapPath("Reports/Agency Summary.xls"));
Warning 12 'Aspose.Cells.WorkbookDesigner.Open(string)' is obsolete: 'Use WorkbookDesigner.Workbook.Open property instead.'
AND
WorkbookDesigner wbd = new WorkbookDesigner();
wbd.Workbook.Save(reportName, SaveType.OpenInExcel, FileFormatType.Excel97To2003, page.Response)
Warning 11 'Aspose.Cells.Workbook.Save(string, Aspose.Cells.SaveType, Aspose.Cells.FileFormatType, System.Web.HttpResponse)' is obsolete: 'Use Workbook.Save(System.Web.HttpResponse, string, ContentDisposition, SaveOptions) method instead.'
I've tried to modify the Open and Save method calls but have been unable to create an appropriate call, for example wbd.WorkBook does not have an Open method or Property and I can't find an appropriate format for Save that allows me to specify OpenInExcel AND Excel97To2003.
Please advise.
Hi,
Thanks for pointing out these issues.
Please use this code for opening workbook in workbook designer.
[Code#1 - C#]
WorkbookDesigner des = new WorkbookDesigner();
des.Workbook = new Workbook(@“F:\Downloads\e0005.xls”);
Please use this code for saving to
HttpResponse stream. Note this is a complete example, which creates a new workbook, put some value in cell A1 and then save the workbook into response stream.
[Code#2 - C#]
//Create a workbook and access its first sheet.
Workbook wb =new Workbook();
Worksheet sheet = wb.Worksheets[0];
//Write value to cell A1
Cell cell = sheet.Cells["A1"];
cell.PutValue("Hello!");
//Save the workbook to http response stream
OoxmlSaveOptions xSaveOptions=new OoxmlSaveOptions();
xSaveOptions.SaveFormat=SaveFormat.Xlsx;
System.Web.HttpResponse responseStream = System.Web.HttpContext.Current.Response;
wb.Save(responseStream, "Hello.xlsx", ContentDisposition.Attachment, xSaveOptions);
responseStream.End();
Hi,
Since Shakeel Faiz has already suggested you in correcting your prior code segments accordingly, I will also recommend you to check the following two documents for your complete reference about Opening and Saving Workbooks:
http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/opening-files.html
http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/saving-files.html
thank you.
Thanks, that fixed that error. I've found one other issue with the upgrade.
We are constructing a spreadsheet that has complex formatting. It is organized by State with a page break for each State, with a variable number of Agency rows in the detail on each page. We have a "template" set of rows at the top of the worksheet which is copied to the rows below where the data is filled in. For each break in State we insert a page break. We used to use ws.HPageBreaks to insert page breaks. I converted those to ws.HorizontalPageBreaks:
ws.HorizontalPageBreaks.Add(currentRow - (TEMPLATE_END_ROW - TEMPLATE_START_ROW + 1), 0);
where the row calculation is based on the current row pointer minus the number of rows in the "template" rows at the top of the spreadsheet. Once the spreadsheet is completely built the "template" rows at the top of the sheet are deleted. This now appears to be throwing off the page breaks that were inserted. Under the previous version it did not. For example the first page break is at row 20 using the calculation above. The code correctly inserts a page break at row 20. The template extends from row 0 through row 23 so at the end of the code we delete it:
ws.Cells.DeleteRows(TEMPLATE_START_ROW, TEMPLATE_END_ROW - TEMPLATE_START_ROW + 1);
where START_ROW=0 and END_ROW=23
This appears to delete the page break that was previously inserted at row 20. Is this new behavior? I tried removing the template length calculation:
ws.HorizontalPageBreaks.Add(currentRow);
But this resulted in the page breaks showing up at the actual rows indicated by the values of currentRow prior to deleting the template rows.
Is the problem that the first page break is within the scope of the template rows that are deleted?
I'm confused. This worked perfectly until I upgraded the app.
I thought I'd come up with a solution:
- I moved the template to a separate worksheet named "Template" and removed the template rows from the target worksheet.
- I updated my method to copy rows to accept a "from" and "to" worksheet, "from" being "Template".
- I updated my page break method to insert at the current row:
ws.HorizontalPageBreaks.Add(currentRow, 0);
Running this in debug I should have page breaks at rows 21, 60 and 80. If you look at the attached resulting XLS the page breaks are not at those rows. I'm even more confused now.
Further information:
I ran the program in Visual Studio 2008 in Debug mode. The code to insert page breaks is:
//Print each State
foreach (DataRow drState in dtStates.Rows)
{
//Print this State's data
printState(dsReport, drState);
//Insert page break
insertPageBreak();
}
//Insert Page Break
private void insertPageBreak()
{
ws.HorizontalPageBreaks.Add(currentRow, 0);
}
I put a watch on the currentRow variable and it incremented correctly based on the layout of the final XLS file, however the page breaks were still not in the correct places in the file. I added a ws.HorizontalPageBreaks.Clear() right after instantiating the worksheet to make sure there were no pre-existing breaks. That didn't fix it. I then added a watch on ws.HorizontalPageBreaks.Count and despite invoking the insertPageBreak method 15 times with 15 different values for currentRow the count never incremented. After the last state was processed and just before saving the file the value for HorizontalPageBreaks.Count was still 1. Is this correct behavior? Am I missing something in the process of adding page breaks?
Hi rschaeferhig,
To help us know your problem better, please extract your relevant code and make some console application. We will then look into it and help you resolve your problem. Please also give a try to latest version of Aspose.Cells for .NET 5.2.2.3.
I updated to Aspose.Cells 5.2.2.3 and I still have the problem. It will take me a while to build a demo app for this problem. The actual app is very complex.
I can state categorically however that per my previous post it appears that despite calling:
ws.HorizontalPageBreaks.Add(currentRow, 0);
At the appropriate points in the process (15 times) with the appropriate values for currentRow, the ws.HorizontalPageBreaks.Count stays at 1. It appears that the above call to insert a page break, while not throwing any error, is not inserting a page break. This is borne out by the fact that the resultant spreadsheet only has the default page breaks dictated by page length.
I created and emailed a ZIP file with a full VS2008 solution that emulates the code in our app in a more simplistic structure. It has the same issue with inserting page breaks as the original app. The test app is a web app since that was simpler to construct based on the existing code. You can replicate the problems easily by running the app under debug in VS2008.
Hi,
Thanks for sending a sample web application to me. I have tested your code and commented just one line, now everything works ok. Please see the attachments of output xls file and your code modified by me.
Please also see this screenshot for further illustration.
That fixed it. Thanks for your help.