Opening xls file and enabling save mode and save it using C# - excel

I downloaded an xls file from a website and I need to convert to csv for further parsing . I used a 3rd party library to do this, But the xls file doenst open as it. But after I open the file in excel and saving it manually, it works. I am not sure what is happening. can somebody let me know how to write a c# code to open xls in Excel and enable saving , save it and close it?. If I can do this programtically I am all set.

Related

The file format and extension of filename.xls don't match. The file could be corrupted or unsafe

My code exports an excel (.xls) file as HTML from a webpage. On opening this downloaded file, I get an error saying:
The file format and extension of filename.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?
On clicking yes, it displays the contents correctly. Is there a way to get rid of the warning?
Other questions addressing this error have suggested changing the extension from .xls to .xlsx, but that completely prevents the files from opening in my case.
To clarify, I am not importing HTML data into an excel spreadsheet. I am representing an excel spreadsheet as HTML. I can share the file if required.

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.

Need to monitor user downloads folder for new .xlsx files, then open Excel, save the file, and close Excel

At work I use a tool that requires me to download a .xlsx file, open it, then save it to remove the workbook protection. I'd like to create a script that automatically opens and saves any .xlsx files that are saved in the downloads folder.
I'm assuming PowerShell is the right tool to use. I found this article that explains how to do something similar, but I need help with configuring the parameters.
https://social.technet.microsoft.com/Forums/scriptcenter/en-US/1faa97e0-2288-4bb2-b8ad-283df32779d4/can-i-open-an-excel-workbook-when-files-with-a-certain-extension-are-saved-in-a-specified-folder?forum=ITCG
What I need is for the script to monitor the $env:USERPROFILE\downloads folder for any .xlsx files. Then I need it to open that file in Excel (preferably in a minimized window), save it with the same filename, then close Excel.
You can use IO.FileSystemWatcher to monitor a directory. See Start-FileSystemWatcher for an example implementation in PowerShell.

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.

SWT OleClientSite: How to load XML file in 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

Resources