I'm already generating an excel XML file (.xml) containing 2 worksheets.
issue #1:
the people downloading the XML file wouldn't know to open the file in Excel. (they'd complain.)
solution #1:
I rename the file to .XLS instead of .XML.
issue #2:
when opening the file in Excel i get the this error:
The file you are trying to open, ‘XXX.xls’ is in a different format than specified by the file extension. Verify that the file is not corrupted and is from a trusted source before opening the file.
Solution #2:
Convert the XML file to XLS file somehow.
so here's where i turn to you...
Goal:
they need to be able to open the file by double-clicking it.
i don't want to have to rebuild the excel file using some 3rd party library.
Ideas:
perhaps convert XML to xls using tools like the following:
http://npoi.codeplex.com/
http://excelpackage.codeplex.com/
I'd need some sample code of the simplest and LITEst way of achieving this.
any other ideas?
Just a random thought: if you're generating XML for people to open with Excel, why not generate XSL (or maby XSLX) in the first place?
Related
I use the FlexCel library to create an Excel report in the .xlsx format.
When creating a file in .xls format - everything works fine.
When I try to create a file in the .xlsx format, the file is created, but when I open it by Excel, I get an error that the file is corrupt and can not be opened. And the file has the size in half from .xls.
If someone has encountered a similar problem or knows a solution, I will be very grateful for the answer.
Edit:
My code
var templateFilePath = "D:/template.xlsx";
var newReportPath = "D:/report.xlsx";
using (var fr = new FlexCelReport(true))
{
fr.AddTable("SOReport", dataTable);
fr.Run(
templateFilePath,
newReportPath
);
}
I had the same problem with export in xlsx format with old versions of FlexCel.
Currently I've tested it on FlexCel v5.5.1.0 and there is interesting behaviour:
If I use Excel 2016 or above to create xlsx templates - then I get "file is corrupted" error while trying to open exported xlsx file.
But if I use Excel 2013 or below to create xlsx templates - then I can open it perfectly without errors.
Also mention that if you open xlsx template created by Excel 2013 or below in Excel 2016 or above and save it - you can't restore it to working state in the future. Template will lost for you.
Too late but I hope this can help you.
P.S. Probably, FlexCel team (TMS Software) fixed it starting with v6.7.16.0 version of FlexCel. I think so because documentation said something similar: https://www.tmssoftware.com/site/flexcelnet.asp?s=history
Points like Improved : Improved compatibility with invalid xls and xlsx files
But I can't argue that.
I am not able to open .xls file after last Excel update. When I double click on file, Excel starts but do not show any message.
In the past it showed "The file you are trying to open, 'filename.xls', is in a different format than specified by the file extension. Verify that the file is not corrupted and is from a trusted source before opening the file. Do you want to open the file now?" and I was able to open it.
I am generating this file with C# and xsl stylesheet. When I open file in Notepad++, add space somewhere and save it - file is suddently possible to open.
How to fix this? Where can be a problem?
Thank you for help.
We are in the process of migrating the documents from AppXTender ( a EMC Documentum tool ) to another system.
I took a XLS file from AppXtender physical store ( the tool have renamed the .XLS file to .BIN ) and I knew its an excel file I tried renaming it to .XLS but the file is not opening as excel.
I learnt that the file is been modified by the AppXtender with some content like, "FFL 1.0 followed by the original file name.XLS".
When I open the excel in a notepad I could see this in the first line and there are couple of more lines with some text like "Embedded" and with some number.
If I manually remove those lines and save the file and still the file is not opening as excel.
What are these custom texts? how do i programmatically (C#) remove them from the excel file and restore as the proper excel file?
Thanks!
Karthik
We have a class library project that is using Gembox which we use to create pdf files. Part of the workflow is to read templates from .docx files. We would like to embed these word file in the dll file that is created by the build, at the moment they are placed next to the dll file in the bin-folder.
Any suggestions in how we can solve this?
Add them to your resources file:
Then you can access them like this:
byte[] fileData = ProjectsNamespace.Properties.Resources.file;
I am saving as any file to .xlsx format. If the original file is not with .xlsx extension, it is throwing exception while trying to open it. The exception message is :-
Excel cannot open the file 'abc.xlsx because the file format or file
extension is not valid. Verify that the file has not been corrupted
and that the file extenstion matches the format of the file.
Whereas if conversion is in .xls format, I can open the converted file with warning message.
The file you are trying to open, abc.xls, is in a different format
than specified by the file extension. Verify that the file is not
corrupted and is from a trusted source before opening the file. Do you
want to open the file now?
I need to convert file to .xlsx format by C# code regardless its extenstion and open it by Excel 2010.
Thats not how file-types work!
You can not simply rename a file and it gets converted to a different type.
Renaming *.xls to *.xlsx works, because both are Excel files which can be opened by MS Excel, but for all other types (except some other which Excel can handle, like e.g. *.csv) you need to read the file and "manually" convert them.
To write *.xlsx using C# you can use e.g. EPPlus (NuGet).
You need a library that convert the files for you.
I see that you need to open files from Office 2003, so you need to use something like NPOI
Unfortunately, even if EPPLUS is a great library for Office's files, it only support the OXML Documents like .xlsx or .docx but not the .xls.
NPOI is a free opensource library to work with Office 2003->2010/3 files.
Here is the link