Is csv possible with multiple tabs / sheets?

I'm calling the web service, and the data from the web service is in csv format. If I try to save the data in xls / xlsx, I get several sheets in the book. So how can I save data in csv using multipletab / sheets in C #.

I know that csv with multiple tabs is not practical, but is there any damn way or any library for storing data in csv with multiple tabs / sheets?

+16
c # excel csv
source share
4 answers

CSV, as a file format, accepts one “table” of data; in Excel terms, that is one sheet of workbook. Although this is plain text and you can interpret it in any way, the “standard” CSV format does not support what your supervisor thinks.

You can invent what you want in several ways:

  • Use a different file for each sheet with related but different names, for example, "Book1_Sheet1", "Book1_Sheet2", etc. You can then find groups of related files in the text before the first underline. This is easiest to implement, but requires users to go across multiple files into one logical “workbook,” and if you get lost in shuffling, you lose that data.

  • Follow the above steps, as well as "write" the files in one archive, which you can move. You retain the sheer CSV advantage in the above option, plus the convenience of moving one file instead of several, but the disadvantage is that you have to zip / unzip the archive to get the actual files. To ease the pain, if you are running .NET 4.5, you have access to the built-in implementation of ZipFile, and if you are not using DotNetZip with open source code or SharpZipLib, any of which will allow you to programmatically create and consume standard Windows ZIP files. You can also use the almost universal combination .tar.gz (aka.tgz), but your users will need either your program or a third-party compression tool, such as 7Zip or WinRAR, to create an archive from a set of exported CSVs.

  • Introducing a quasi-CSV format where an empty row (containing only a new row) acts as a “tab delimiter” and your parser expects a new row of column headers, followed by rows of data in the new configuration. This version of the standard CSV may not be read by other CSV users, because it does not match the expected file format, and therefore I would recommend that you do not use the ".csv" extension, as it will confuse and frustrate users waiting to be able to open it in other applications such as spreadsheets.

+10
source share

If I try to save the data in xls / xlsx, I get several sheets in the book.

Your answer is in your question, do not use text / csv (which, of course, can not do several sheets, it can’t even make one sheet, there isn’t such a thing as a sheet in text / csv, although in some applications, like Excel or Calc, want to import them into a format that has sheets), but save it as xls, xlsx, ods or another format that has sheets.

Both XLSX and ODS are much more complex than text / csv, but perhaps the simplest of their respective sets of formats.

+5
source share

I have been using this library for a while,

https://github.com/SheetJS/js-xlsx

in my projects for importing data and structure from such formats as: xls (x), csv and xml, but you can probably save in these formats (everything from the client)!

Hope this helps you, watch the online demo,

http://oss.sheetjs.com/js-xlsx/

take a look at the source code or write a question about GH? but I think you will have to do most of the encodings on your own

+3
source share

I think you want to reduce the size of the Excel file. If so, then you can do this by saving it in xlsb format, that is, in Excel binary workbook format. In addition, you can reduce the file size by deleting all empty cells.

0
source share

All Articles