C# How to create an Excel 5.0/95 file - c#

I need to create (save) an Excel 5.0/95 file with C# (to be use by an old software), but I'm stuck in not finding the necessary library.
Till this point I always used "EPPlus" (for .xlsx format) and "Excellibrary" (.xls format Excel 97-2003), and couldn't find a way to change the format in any of these two to save the Excel in 5.0/95.
Someone know how to do this?

Related

How to identify an excel file(xls, xlsx, csv) which has been converted from .DLL file in c# dot net core

Basically need to identify the excel is originally created from a valid excel. I have tried using Microsoft.Interop.Excel File format.
Seems like I cannot use this without Microsoft office being installed. So need another approach for this problem.
EDIT :
Basically I want to be able to distinguish a valid excel from invalid one like an excel file which is converted from DLL. Because the file extension will say it is xls. If you try to open that file, it will open an empty workbook without any sheets. But I cannot decide an excel with no sheets is an invalid one.
If you want to idenify wheter file is a valid excel file or not, you can use 'trid file identifier'. TrID - File Identifier.
You can do it own your own also by reading magic number or file signaure bytes. Please go through this question Original file bytes from StreamReader, magic number detection.

Reading non-standard excel file with C#

What do i mean by 'non-standard'?
Take a look at these images: http://imgur.com/a/tFqHQ
The first one is the non-standard excel file. I'm pretty sure it's not an excel file, but the file's extension is .xls and for some reason Excel can open it, and understand it's structure.
The second image is the same file after it was opened in excel, and saved out to .xls (97-2003).
If excel can open it, and view it correctly, i should be able to do as well. Any tips how to approach this?
I have to mention that, my app have to use and read the non-standard excel files, because otherwise the user have to open the files one-by-one in (excel/libre office) and save it out in a correct format, which i would like to avoid for convenience.

Strip Excel file of Macros with C#

I've been asked to strip an Excel file of macros, leaving only the data. I've been asked to do this by converting the Excel file to XML and then reading that file back into Excel using C#. This seems a bit inefficient to me and I was thinking that it would be easier to simply load the source Excel file into C# and then create a new target Excel file and add the sheets from the source back into the target.
I don't know where macros live inside an Excel file, so I'm not sure if this would accomplish the task or not. So, will this work? Will simply copying the sheets from one file to another strip it of it's macros or are they actually stored at the worksheet level?
As always, any and all suggestions are welcome, including alternate suggestions or even "why are you even doing this???". :)
To do this programmatically, you can use the ZipFile class from the System.IO.Compression library in .NET from C#. (.NET Framework 4.5)
Rename the file to add a ".zip" extension, and then open the file as a ZIP archive. Look for an element in the resultant "xl" folder called "vbproject.bin", and delete it. Remove the .zip extension. Macros gone.
Your best bet is to save the workbook as an xlsx, close it, open it, then save as a format of your choice.
This will strip the macros and is robust. It will also work if the VBA is locked for viewing.
Closing and reopening the workbook is necessary otherwise the macros are retained.
If you're needing to use C# to do this, I agree that it would be easier to load the source Excel file into C# and create a new target file only copying over the cells and sheets you need. Especially if you're doing this for a large amount of excel files I would recommend just creating a small console app that, when given an excel sheet, will automatically generate a new excel sheet with just the data for you.
One tool that I've found extremely useful and easy to use for such tasks is EPPlus.

Converting PDF values to excel in specific format

I have some plain data in a PDF as shown below.
I need to get this data and convert it to put in an excel file like this
I am confused if there is a direct method in Microsoft Excel 2007 and above to directly take values from PDF and paste it in this format.
So far what I've tried is itextSharp with C# coding. It doesnot seem to support convertion from PDF to excel and even though I've tried, I couldnot get in this format of excel. I shall put updates to my further findings in this question itself.

How use clipboard to move data from .NET application to Excel?

Which is Excel's preferred format for receiving data from the clipboard? The data is in a C# / .NET application.
I had been saving to the clipboard in CSV format, but now I want to start giving Excel formatting information (eg. make some cells bold). CSV format is no longer enough.
When I copy from Excel, the clipboard holds 24 formats!
System.Windows.Clipboard.GetDataObject().GetFormats().Dump();
EnhancedMetafile
System.Drawing.Imaging.Metafile
MetaFilePict
Bitmap
System.Drawing.Bitmap
System.Windows.Media.Imaging.BitmapSource
Biff12
Biff8
Biff5
SymbolicLink
DataInterchangeFormat
XML Spreadsheet
HTML Format
Text
UnicodeText
System.String
CSV
Rich Text Format
Embed Source
Object Descriptor
Link Source
Link Source Descriptor
Link
Format129
*
I believe what you're seeing is that Excel prepares the data when you copy to the clipboard in many different formats depending on where you end up pasting it. You probably need to look into the Office XML format for Excel.
See this example xml at Wikipedia for a better idea of the format. While I've never used it before, I'm pretty sure Excel would simply let you paste in the XML directly (if it's the right schema).

Categories