Read xls file using OpenXml [duplicate] - c#

This question already has answers here:
How to read the xls and xlsx files using c#
(3 answers)
Closed 8 years ago.
I am using OpenXml for reading excel file into DataTable from c#.net.
Its going all well for xlsx file but it is giving me exception as "File Contains corrupted Data" when trying to read xls file.
Is there any way to read xls file using OpenXml from c#.net application????
Please help.
Thanks.

No, there is no way at all to read XLS files using OpenXML. XLS is the old Excel file format that was the standard until and including Word 2003. It uses XML inside, but not the Office Open XML format used in XLSX files.

Try saving the file in another format, Excel Workbook (xlsx) worked for me when getting the same error.

Related

How to detect in C# if a given file is a valid .docx and not just a .zip renamed as .docx? [duplicate]

This question already has answers here:
Determine the file type using C#
(8 answers)
Check docx is corrupted or not
(2 answers)
Closed 4 years ago.
Currently I'm validating a given file by matching its content and extension using the header information. However, .docx and .zip has the same header info (meaning the first 4 bytes are { 80, 75, 3, 4 } for both).
Now, if someone just rename a .zip file to .docx file, how am I supposed to prevent it? Is there a way to do it without using some 3rd party utility?
I think, you can't preventing a user to rename a file.
In my optinion you can either look inside the zip container and search for characteristic word files and folders like the document.xml or you are using the open xml sdk to be sure to have a valid word file.
https://www.nuget.org/packages/DocumentFormat.OpenXml/

Copy excel template and edit in memory using OpenXML [duplicate]

This question already has answers here:
How do I export to Excel?
(3 answers)
Export DataTable to Excel with EPPlus
(5 answers)
Closed 4 years ago.
My requirement is to open an excel template and edit in memory and then download to user. This needs to be done in .net MVC web project so I tend to use OpenXML instead of InterOp.
The whole idea is I have an excel template which has two sheets. Second sheet contains a set of datasources which I have bound as a range selector in first sheet cells. Now, based on which user is logged in, I need to change the data in datasources and same will be reflected into the first sheet.
This template is added into the project. For concurrency, I don't want to edit this template. I am thinking to either make a copy of this and download it to temp or best if I can take the snapshot of this template in memory and edit the sheet to and then stream it to the response for user to download.
Any help, links, articles based on OpenXML SDK will be really helpful.

How To Determine Which Version of Excel last saved a Workbook [duplicate]

This question already has answers here:
How can I check the version of Excel files in C#?
(3 answers)
Closed 7 years ago.
I have some excel files (.xls) that is being automatically generated from some system, and I am distributing these files to some users and they edit some fields in it and send it back to me.
I need to know from each file they sent me which version of excel they are using (is it office 2003, 2007, 2010, 2013...?) because I want to know what is the lowest versions I need to keed support for.
Is there a way to take these files and get the excel version that saved each one of them ?
I tried this solution Programmatically finding an Excel file's Excel version but it didn't do it...
I believe this is what you are looking for, at least it worked fine for my application.
var excelWB = new OleDocumentPropertiesClass();
excelWB.Open(FilePath, false, dsoFileOpenOptions.dsoOptionDefault);
string FileUsedVersion = excelWB.SummaryProperties.Version.ToString();
Greetings

MS Word Integration in C#? [duplicate]

This question already has answers here:
How can a Word document be created in C#? [closed]
(17 answers)
Generate Word document from c# [duplicate]
(3 answers)
Closed 9 years ago.
I have tried to look around for documentation on this subject, but I haven't really found a concrete answer. Just answers to problems that I am not really facing.
I want to pull some patterns and phrases from a database and generate a docx (or doc?) file in MS Word using C#. It's part of a school project. But the integration part doesn't seem to be very well documented, or I am looking in the wrong places.
Any help with this?
The magic word for google purposes is "Interop". Try this as a starting point:
http://www.dotnetperls.com/word
There are basically two ways to create word documents programmatically:
Create the documents by calling (and starting) word programmatically
Create the word document in the open XML format readable by Word.
For more info see similar questions here on stackoverflow:
How to create word docs programmatically from a template
Try use Open XML SDK 2.0 for Microsoft Office link
It provides easy way to work with docx file.
After words docx format is simple zipped xml file.

Reading an Excel Sheet containing 10000 Rows In C# [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Reading Excel Files as a Server Process
While the Jet OleDB Driver is pretty simple to use for reading an Excel sheet, it simply cant handle excel files having rows more than a thousand.
Is there any other way of reading more than 5-10k rows from an excel sheet in C#?
If it is an ooxml file you can use open xml sdk. It is not as straightforward as the oledb driver, but it is possible.
If you can transform the excel-sheet to a csv-file, you can use Filehelpers. This can handle 100K+ records.

Categories