SWT OleClientSite: How to load XML file in Excel? - excel

I have an Excel file in OfficeML format, MyData.xls. Since I upgraded to Office 2007 from Office 2003 I get a warning message saying that the file content does not match the file extension. It seems that OfficeML now must have the extension 'xml'.
In my application I use OleClientSite to display the file in an OleFrame object. If I change the file extension to 'xml' then Excel is not started. If I leave the extension as 'xsl' then I get the above warning message.
How can I force the file with the 'xml' extension to be opened in the OleFrame using Excel?

The easiest solution is to switch back to the 2003 format, which should not require any changes to your application. To do this, open your file with the extension set to *.xls. When prompted with the warning ("... do you want to open the file now?"), proceed to open (this is a warning to make sure you don't unintentionally open a macro-enabled file). Once in Excel and the file is open, simply save it as *.xls. This can be done by going to "Office Button / Save As / Excel 97-2003 Workbook".
Now, the harder solution will be upgrading your application to deal with the new OfficeML format. I don't know about the component you're using, but it will likely still work for some of the binary parts in the new standard (most notably VBA projects), but you're going to have to unpack and start reading XML files.
If you haven't already done this, create a new Excel workbook, save it as *.xlsx (the 2007 format) and in Explorer, change its extension to *.zip. Open it up and take a look around. For more in-depth on the files, I would start digesting this MSDN article.

Maybe I'm missing something, but shouldn't you just use .xslx as your extension? I'm assuming that by OfficeML, you're refering to Office Open XML.

The <?mso-application progid="Excel.Sheet"?> should be present in the XSL template used.
The below link explains clearly how to include the processing instruction. I had to do something similar and it worked for me.
http://www.shareyourwork.org/roller/ralphsjavablog/entry/generating_excel_sheets_with_xslt

Related

Excel behaves strange with XSLX file created manually

Based on knowledge gained through working with the OpenXML SDK, I have implemented an Excel generator in JS (using TypeScript with ReactJS and a custom JSX factory generating plain XML). The files generated open fine in Excel and one can also edit and save them fine in Excel, no errors.
However, if one tries to copy cells (even a single one) from such a generated Excel file to another worksheet in the same Excel instance, it fails with the error "The command cannot be used on multiple selections.". Just saving and reopening the file is enough to fix the problem. Copying to other applications (e.g. Notepad) works fine.
It seems that this particular error is shown by Excel in several edge cases where the data is not exactly meet the expected format, for instance I found reports of that happening when a sheet is hidden when manipulating it via VBA. However, in my case I'm not sure what could be causing the issue.
Just saving the file in Excel unfortunately significantly alters its parts, so that I couldn't get a meaningful diff out of it. I did not see what could be causing the problem. Maybe someone has some experience with the internals of Excel?
To get a sample file, copy the following into your browser address bar and save it as xlsx file:
data:application/vndopenxmlformats-officedocumentspreadsheetmlsheet;base64,UEsDBBQAAAgIAAAAAAA69A4d5wAAAGYBAAAPAAAAeGwvd29ya2Jvb2sueG1sjZA9T8MwEIZ3JP7DyTt1AAmhKEkXBOqCMgC7Y1+SU/0R3bktPx+3ocxM9/k+9+qa7XfwcEQWSrFV95tKAUabHMWpVZ8fr3fPCrbd7U1zSrwfUtpDEURp1ZzzUmstdsZgZJMWjGUyJg4ml5InLQujcTIj5uD1Q1U96WAoqpVQ838YaRzJ4kuyh4AxrxBGb3KxKzMtoro/Zz3rrrmck98Ikk3GVh1JaPCoIJpQyi/CE/SHwZNdQZBGeGOcEpOJoOAi3rnyDwVcU0l45x5Vwesr3+FIEd17AUrpW+Ntz3AOZ1112b0a634AUEsDBBQAAAgIAAAAAAD2SCbhNwEAAMYCAAANAAAAeGwvc3R5bGVzLnhtbJ1STWvDMAy9D/YfjO+rk8DGGEl6KAR22aUd7OokSmvwF7Zbkv36yXFK20EZ7GJJz++9KLLK9agkOYHzwuiK5quMEtCd6YXeV/Rz1zy9UrKuHx9KHyYJ2wNAICjRvqKHEOwbY747gOJ+ZSxovBmMUzxg6fbMWwe891GkJCuy7IUpLjStS31UjQqedOaoQ0UzyupyMPqCFDQBSOUKyInLim64FK0TkevF9wLmeaxZ4qazvQBz8HghpLz1RqAuLQ8BnG6wIEu+myxUVBsNyGJXhGg2hz+ke8envHi+p54DdtQa1+PYzz3l9Awh5VeC7A6k3MYX+BpuJONA0ijf+zhFEn/3nOJ3ljTZpCLO5toteV/ZFv+yJdxaOX0cVQuumVcgNcjG4b5dftduEbKlt7rsx+F2W9hlIesfUEsDBBQAAAgIAAAAAABh+IC4iAEAAGIDAAAYAAAAeGwvd29ya3NoZWV0cy9zaGVldDEueG1shZNNT8MwDIbvSPy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/irAayVXmMUsEz8QX68Eo1ZQoE1nQDfdAXwquQfA6sXUEsDBBQAAAgIAAAAAAAUVUFPBQEAAJkCAAATAAAAW0NvbnRlbnRfVHlwZXNdLnhtbK2Sv07DMBDGdyTewfJaxU4ZEEJJOkA7AkN5AONcEiv+J59b0rfHcQsDKmXpdLLv+77fneVqNRlN9hBQOVvTJSspAStdq2xf0/ftpnigZNXc3lTbgwckSW2xpkOM/pFzlAMYgcx5sKnTuWBETMfQcy/kKHrgd2V5z6WzEWws4pxBm+oZOrHTkayndH0kB9BIydNROLNqKrzXSoqY+nxv21+U4kRgyZk1OCiPiySg/Cxh7vwNOPle01ME1QJ5EyG+CJNUfNL804Xxw7mRXQ45M6XrOiWhdXJnkoWhDyBaHACi0SxXZoSyi8t8jAcNeG16Dv2HPG+eDchzWV55iJ/87zl4/mjNF1BLAQIUABQAAAgIAAAAAAA69A4d5wAAAGYBAAAPAAAAAAAAAAAAAAAAAAAAAAB4bC93b3JrYm9vay54bWxQSwECFAAUAAAICAAAAAAA9kgm4TcBAADGAgAADQAAAAAAAAAAAAAAAAAUAQAAeGwvc3R5bGVzLnhtbFBLAQIUABQAAAgIAAAAAABh+IC4iAEAAGIDAAAYAAAAAAAAAAAAAAAAAHYCAAB4bC93b3Jrc2hlZXRzL3NoZWV0MS54bWxQSwECFAAUAAAICAAAAAAAjzovrLwAAACZAQAAGgAAAAAAAAAAAAAAAAA0BAAAeGwvX3JlbHMvd29ya2Jvb2sueG1sLnJlbHNQSwECFAAUAAAICAAAAAAAY2vxKKkAAAAZAQAACwAAAAAAAAAAAAAAAAAoBQAAX3JlbHMvLnJlbHNQSwECFAAUAAAICAAAAAAAFFVBTwUBAACZAgAAEwAAAAAAAAAAAAAAAAD6BQAAW0NvbnRlbnRfVHlwZXNdLnhtbFBLBQYAAAAABgAGAIABAAAwBwAAAAA=
Well, I don't know the particulars of how you are generating the xml file, but I can tell you how to edit the underlying xml files so that it will work, and then perhaps you can figure out how to use your implementation to change the property that's gunking things up.
First, an xlsx is a set of xml files. I'm sure you know that, but I'm just starting at the beginning. You can change the extension to zip and then extract the files, and then rezip them and change the extension back to xlsx.
So do this:
take the generated xlsx
change the extension to .zip
extract the files
find xl\worksheets\sheet1.xml
open it and find this property: worksheet>sheetViews>sheetView:tabSelected
set it to 0
save the file
go back to the unzipped folder
select all files and send to zip
change the extension on the new zip file to .xlsx
You should now be able to open the newly created xlsx, add a new sheet, and copy freely.
If this works for you, then you have diagnosed the problem, one property set to true when it shouldn't be, and it should be relatively simple for you to modify your export procedure.
I've had this issue multiple times in the past.
The way I solved it was by filling out (populating) a template (file, previously created in Office) with the exported data rather than generating a file from scratch. Office unfortunately does not fully comply with OpenXML, and for more complex exports you might even be unable to open the file.
I would also recommend Beyond Compare (now Scooter Software) for comparing the two files instead of just doing a diff.

Can I programmatically enable and disable ms-excel file sharing / co-authoring of an xlsx file stored in SharePoint and linked to ms-access?

We have a ms-excel xlsx file stored in SharePoint. This file can be edited in two ways: directly in SharePoint or through ms-access acting as a front-end of the xlsx file (as an external linked table). We want the xlsx file to be edited while the ms-access database is open.
While ms-access is open, the xlsx file appears as read-only. We want programmatically disable the read-only state, so that other people could edit the xlsx file while ms-access is open and, also, enable read-only again when necessary.
I think that the only way to get this is by sharing the xlsx file. My question is as follows:
I don't know whether the best way to share the xlsx file is using co-authoring or using the standard ms-excel sharing. We tried to do it manually using co-authoring, but the xlsx file could not be edited through ms-access.
If we manage to edit the xlsx file through ms-access, then, is it possible to change the shared status programmatically while ms-access is open throug VBA, .NET, VSTO, MS-Javascript API or any other language? I have searched in Google, but I have found nothing but some .NET library for ms-word (Microsoft.Office.Interop.Word.CoAuthoring), but, curiously, not for ms-excel and, as the great wise Confucius said, "if you search something in Google for more than three hours and you don't find it, this means that it doesn't exist".
But maybe someone has had this same odd problem and could help us.
Thanks in advance.
You can't. The first application to open the file will "hold" it, and the next will either could open it as read-only or not at all.
You may be able to let Access open the Excel file, import the data to a table, and then close the file. If the file already is opened in Excel, it may fail, and that you must, of course, take care of.
Another option could be to have a function in Excel that exports the data to another workbook, and then let Access read this.

Importing .xls to Access .mdb: External Table is not in the expected format

I have a macro that imports a spreadsheet as follows: (this spreadsheet is an export from a web-based application, and during the initial export the chosen format is 97-2003)
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12, "d2s_safety_tbl", _
"\\company.com\dfsroot$\Share\office_public\D2S\D2S\D2S_Scorecard\Source Data\D2S\D2S Safety.xls", True
When importing to Access, I get:
Run-time Error '3274': External table is not in the expected format.
When I open this Excel file, I get a dialog
"The file you are trying to open is in a different format than specified by the file extension..."
So the file name is .xls, my computer tells me its the 97-2003 Format, but once I open the file and click save, it defaults to save it as a Web Page format with the option to save as .xls. What gives?
UPDATE: If I open the file, then Save As .xls format (seemingly redundant, but apparently not), it asks me if I want to overwrite the existing file, so I do. Once I go through this, the VBA import is successful. I can't have the clerk go through this process every week--any way to avoidd this? Possibly the initial export from the web-based application?
DoCmd.TransferSpreadsheet is refusing to import your .xls file because it is not really an .xls file, it is an HTML file that has been given an .xls file extension. Providing a "fake" file extension is a trick that I've seen other "developers" use, and it really is a Bad Idea (for the reasons we've seen here).
If the keepers of the upstream system balk at doing The Right Thing and fixing their code to produce a real .xls file then try renaming the ".xls" file to .htm and importing it using
DoCmd.TransferText acImportHTML, ...
I also got a 3274 error when importing a spreadsheet into Access. I have been using this macro for a while now.
The solution was to compact and repair the Access database.
I had the same problem along with another problem (office 2016 x64): Pasting from excel to access raised 'Data on the Clipboard is damaged,...' error. I found a workaround by clicking on the lower right button in paste section of home tab of access, opening the clipboard pane.
After opening Clipborad Pane as stated above, my DoCmd.TransferSpreadsheet surprisingly worked fine.
I don't know why but it may help those having the same problem and those trying to find a real solution.

an HTML file is NOT an Excel file, right?

we use an application that has an "export to excel" feature that doesn't work on PC's that done have outlook express installed.
i know, you're thinking "WTF does outlook express have to do with excel files?"
i asked the same thing, and here's what i found:
the file being generated is actually one of those Microsoft Single File Web Pages (.mht) and NOT an excel file
you need to have outlook express installed to actually view a .mht file.
i've explained to their support people that just because you can slap a .xls on a file and excel will open it does not mean its an excel file, and does not mean that this is the right way to do it.
how would you explain that this is not proper?
Many people (especially managers) confuse Excel files with reporting files. In my opinion, a file is only qualified as an Excel file if it meets all of these conditions:
Is a spreadsheet formatted in one of the many Microsoft Excel formats.
Can be opened in the most recent version of Microsoft Excel.
Is editable in Microsoft Excel.
In your case, I'm guessing only condition #3 is met, so it's no Excel file. But your support people may still call it a reporting file.
If a clean Windows image with only Excel installed can't open it, then it isn't in Excel format. Period.
If a Windows machine with Outlook Express, but without Excel can open it (if you change the extension) then it can't be an Excel file. I'd combine that with Ignacio's suggestion for a slam-dunk.
Plus, surely if it's MHT, then you can't actually do spreadsheet operations on it? Or am I misunderstanding how it works?
I don't think your statements are correct. Excel (2007) has import and export filters for single-file HTML documents (.mht) even if there is no Outlook Express installed. However, this is not a native format and worksheet features such as formulas cannot be retained (see http://office.microsoft.com/en-us/excel/HP100141051033.aspx#7)
So what you should make clear to your customers is that there is a difference between an applications native file format and a format which isn't designed to contain spreadsheet functionality and that is only supported via an import/export filter.

ColdFusion 8 always opens .XLS, want .XLSX

I am using ColdFusion 8. Doing something like this:
<cfheader name="content-disposition" value="attachment; filename=abc.xlsx">
<cfcontent type="application/msexcel">
<html>
But I get a file like abc.xlsx.XLS.
The reason I'm trying to get an XLSX is because sometimes the XLS version is so large and Office 2007 gets stuck opening it or takes way to long.
Only workaround right now is to wait, open the XLS in Office 2007, save as .XLSX and then open it faster.
Any help is appreciated!
I would suggest that the slow opening is because you are providing the data in an HTML format, not because of the extension. You could test this by saving the file directly from the browser, renaming it with the xlsx file extension, and opening it.
If you want to save data in an Excel format directly, I would check out Ben Nadel's POI CFC project.
I believe that the MIME type for Excel 2007 .xlsx files is "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet". I found an article on the Office Resource Kit Blog that calls this out after googling around a little.

Resources