Sometimes Excel fails to open .xls or .xlsx files with UTF-8 with right encoding and I couldn't find any encoding settings for a particular file when writing. How does Microsoft Excel detect encoding of .xls or .xlsx files?
Up to now, my research is:
.xls format is used for Office 97 to Office 2003(inclusive), called BIFF8 format. The text data inside is always encoded as UTF-16. So when Excel 97 opens an .xls file, no detecting is needed.
.xlsx format is used for beyond 2003 and is an XML format. I'm not sure if specifying encoding at top XML level is valid to Excel or has any significance.
Related
I have a large project with Excel VBA files. Planning on moving from the xlsm file format to the xlsb (Excel binary). When I save the xlsm file as an xlsb I get warning.
It displays "abc.xlsm contains features that this version of Microsoft Excel can't save in another file format. Do you want to continue saving in this format and remove these features?"
Didn't know that xlsm can contain stuff that xlsb can't. Would be curious to know what exactly that is.
Anybody got an idea what the problem could be?
I need to convert some txt files to ANSI encoding. These files should have ANSI encoding according to Notepad++ encoding description.
I compare these files to a sample file which is identified by Notepad++ as ANSI encoded. These files should have ANSI encoding to be able to upload them to an old application.
I need to do it automatically as a part of VBA code which I also use to create the files from Excel data. Each time the macro pastes data from Excel to new workbook and saves as text file. Maybe it is possible to just choose encoding while saving Excel file but I didn't find the ANSI encoding in save options in Excel.
I figured out that maybe the best way would be to open each text file in Notepad and save as choosing the ANSI encoding. Is it possible to do using Shell call in VBA ?
I'm creating an excel file using EPPlus from a datatable and saving it to a file, all fairly standard. This works without any hassles. However, if I create a vba project, and add any vba code, the resulting .xlsx file is suddenly corrupted. When try and open it with 2013, you get the standard error.
"Excel cannot open the file 'xyz.xlsx' because the file format or file
extension is not valid. Verify that the file extension matches the
format of the file.
If I change the extension to .xls, the file opens ok, and the script runs fine. I'm on the latest beta of Epplus (4.5.0.1). Should I just change the file extension and stick to .xls, or is there something amiss?
ExcelPackage.Workbook.CreateVBAProject()
ExcelPackage.Workbook.CodeModule.Code = "'Script is here"
Dim FInfo as new FileInfo("C:\Myfiles\ThisFile.xlsx")
ExcelPackage.SaveAs(FInfo)
You can not add VBA code to XLSX file format.
Take a look at here
.xlsx:
The default XML-based file format for Excel 2007-2013. Cannot store
Microsoft Visual Basic for Applications (VBA) macro code or Microsoft
Office Excel 4.0 macro sheets (.xlm).
Also take a look at here
to see differences between different formats:
XLSM If you include VBA macros in your XLSX file, you will be asked to
change the file extension to XLSM. Only that way you can save your
macro within the Excel file (there are other file types possible, e.g.
XLSB – but you can’t use XLSX for VBA macros)
Save your file as XLSM and it should work.
I use Display tag in Struts 1.3 to export a table to .xls file.I can export this without any problem and I can open this file with a text editor and view or edit.
<display:setProperty name="export.excel.filename" value="Export.xls"/>
Then created .xls file in Excel 2003 and try to edit it with text editor, but it's binary file.
The file size created with Excel is much bigger comparing to exported file.
Furthermore, When I try to open the exported .xls file in Excel 2013 it gives following popup,
"The file format and extension of 'Export.xls' don't match.
The file could be corrupted or unsafe.
Unless you trust its source ,don't open it.
Do you want to open it anyway ? (Yes/No/Help)"
What is the reason for this?
I found the reason behind this.The exported Excel(.xls) from displaytag is text-based excel and not a POI-based excel.But Excel application creates binary .xls file.
I am generating csv files to be imported in Adwords Editor. My problem is that I have to open the csv in Excel and save it again because the Editor doesn't encode the characters correctly.
How can I find which character encoding is being used by Excel when saving a csv?