convert .csv to .xlsb programatically c# - c#

Is it possible to convert a .csv file to .xlsb programatically ?
(Preferrably C#)
Convert XLS to XLSB Programatically?
shows how to convert XLS to XLSB , can I use the same to convert it from.csv? Won't there be any formatting issues?
I am doing this on the server side because the .xlsb file size is very small compared to a .csv file, and I don't have an option of zipping my file.

Take a look at EPPlus. I have used this extensively with great success. Fantastic Excel library and it's open source.
And, yes, there certainly will be formatting issues. You cannot go from XLS to CSV and maintain any of the original formatting because .CSV is pure text.

Aspose.Cells File Format API can convert your CSV file to XLSB format. Please see the following sample code and screenshots for your reference.
C#
// Directory path for input and output files.
string dirPath = "D:\\Download\\";
// Load your sample CSV file inside the Workbook object.
Aspose.Cells.Workbook wb = new Aspose.Cells.Workbook(dirPath + "sampleConvertCSVToExcelFormats.csv");
// Save CSV file to XLSB format.
wb.Save(dirPath + "outputConvertCSVToExcelFormats.xlsb", SaveFormat.Xlsb);
Screenshots of Sample CSV and Output XLSB files
Sample CSV File:
Output XLSB file
Thank you and regards.

Related

Howto convert a hex string into a file (OOXML document)

I have a SQL Server 2008 database from an application which stores office file templates.
The files in the database are stored in hex format (0x504B030414000600...).
With a file signature table (https://www.garykessler.net/library/file_sigs.html), I can find out which file format it is: Microsoft Office Open XML Format Documents (OOXML, like DOCX, PPTX, XLSX ...).
How can I export/convert these hex strings into the original files?
Maybe with C# ...
With the application itself, I can only export 1 file at a time. It would take days to do this with all files (about 1000).
Thank you
Export column with files from SQL Server to single file (it may be very large, but it shouldn't matter). You can for example right click and export results to CSV file.
Write simple C# console application:
use CSV parser to loop over data
inside loop you can make simple if statements to determine document file format
in every iteration convert hex format to blob file and save it somewhere on your drive

read matlab mat file via VBA or C#

I have some matlab data files, extension .mat
I want to know if it is possible to read the data in the mat file and then output this data to an excel spreadsheet using VBA, so with code written in the excel workbook or using C#
I have seen you can convert mat files to xls files however I do not wish to do this. I was hoping you could read the .mat file in the code and then select the data you wish to output to the excel spreadsheet
You want to import the code from a .m file? Yeah, you can do that. Just import the data, which is simply stings of code.
Data > From Text > Import

C# File open / convert and save

I am very new to C# and hoping this is a simple question. Not finding what I need on google
I have a file C:\test\losses.csv
That I want to open up then convert to an xlsx file and save in a different directory.
Save to
C:\test\Losses.xlsx
The reason for opening the file is the move command does not convert it to xlsx, unfortunately it keeps the same structure as the csv and is unusable in that format.
File.Copy(#"C:\test\losses.csv", #"C:\test1\Losses.xlsx");
The above code works great but still is a csv file (well really a hybrid of one). That is another SAP story.
Any help will be greatly appreciated. Thanks
File.Copy only copies the file - similar to copying a file in DOS or in windows file explorer.
You'd need to translate your CSV to an XLSX file. The format should be pretty straight-forward, but you'll need to do more research:
Load the CSV as a data table
Use the Excel.XlFileFormat.xlOpenXMLWorkbook class to translate the file.
A different StackOverflow problem addresses how to use the xlOpenXMLWorkbook:
Exporting to .xlsx using Microsoft.Office.Interop.Excel SaveAs Error
Hope this helps. Good luck.

OPEN XML to Export 2007/2010

In my application I already have functionality to export into 2003 format. Where I am constructing a string out of the template and write using System.IO.File.WriteAllText.
But it does not work with excel 2007/2010, that's why I wanted to convert it to Openxml in order to support 2007 and 2010.
I have string ready with creation of cells and rows from template.
I want advice on how to achieve or any body has reference link.
Please let me know.
Regards
WriteAllText class will save you a text file. You are saving an html(text) based file with xls extension. This is not a real xls file (that is actually a binary file), but MS Excel recognize and interpret the html format.
An xlsx file is a binary file. You can use OpenXML Office library ( Excel.XlFileFormat.xlOpenXMLWorkbook ) or another .NET Excel library like EasyXLS. Check this sample of code for more details.

Save .xls file into .txt file in C#.Net

How to save (in fact Save As) .xls file into a text file from C#. I tried File.Copy() but I am unable to see data. I am getting some special characters in the text file.
Any help would be appreciated.
You should use the Microsoft.Office.Tools.Excel.Workbook.SaveAs() method

Categories

Resources