I’m replacing tags in both header and footer in a XLSX document. For XLS, the following code works fine, but for the XLSX documents, I’m getting an inconsistent output file. I’m attaching the XLSX file for sample. My code is:
I guess the sample file you have attached is the output. To investigate your said issue, we need your input file as well as complete source code. It would be of great help that you provide us a simple console application that could re-produce the error as described by you.
Right now, we tried a simpler version of your source code with latest release of Aspose.Cells for .NET and set the header/footer of your file [Excelxls.xlsx]. After re-saving the file we find both XLS and XLSX files consistent in this regard. My both output files are attached for your reference.
Well, that was my input file. I’m trying to replace the text which starts with “##”.
And the complete source code doesn’t affects the file after that. I’m just replacing the tags with a Hashtable. I wonder if the code I’ve provided is the best way to do the header/footer replacing. Do you think I can do it easier?
By simpler source code, I meant without using the HashTable. Now I can reproduce the inconsistent results while saving the output to XLS and XLSX files with my below source code. So I have logged an Investigative Ticket to probe further into this matter. Ticket ID for your reference is CELLSNET-28200. We will keep you posted on this.
C# Code
Hashtable htTagsRegs = new Hashtable();
htTagsRegs.Add("##CodDoc", “CodDoc”);
htTagsRegs.Add("##NumRev", “NumRev”);
htTagsRegs.Add("##TitDoc", “TitDoc”);
htTagsRegs.Add("##DatCri", “DatCri”);
htTagsRegs.Add("##NmeApr", “NmeApr”);
htTagsRegs.Add("##TipCop", “TipCop”);
htTagsRegs.Add("##DatImp", “DatImp”);
htTagsRegs.Add("##SigUni", “SigUni”);
Workbook xls = new Workbook(“C:\temp\EXCELXLS.xlsx”);
I’m sitll getting an inconsistent file as output with the latest version. I’m attaching the output file for your reference. Headers and footers are missing. My code is:
I have tested your source code with latest version of Aspose.Cells for .NET v5.3.3.5 and your template file [ExcelXLS.xlsx]. I find no issue in Header or Footer of my both output files. They are attached for your reference.
Thanks for providing the HashTable values. Now I am able to re-produce the said problem, so I have re-opened the ticket associated with this thread. Also I have added your comments to it. We will sort this out very soon and let you know here.
Further investigation on your said issue revealed that in your output file the character limit for Header or Footer exceeds the limit provided by MS Excel. Excel Headers and Footers have limit to the number of 255 characters, Excel 2007 will reject an entry of more than 255 characters. As to this case, the Header’s character number is 297, so MS Excel 2007 drops the header and footer when you open the output document.
In order to bypass this limit, there are two methods:
Reduce the character number to less or equal 255.
Use picture to replace character. [Please see PageSetup Class for methods SetHeaderPicture and SetFooterPicture]