Convert csv to xlsx linux

Convert a CSV file to a XLS file on the linux command line? [closed]

Questions on Server Fault must be about managing information technology systems in a business environment. Home and end-user computing questions may be asked on Super User, and questions about development, testing and development tools may be asked on Stack Overflow.

I’m using Debian Linux and I want to convert a CSV file to an Excel XLS Spreadsheet file. The catdoc package includes the xls2csv command that converts from XLS to CSV. However it doesn’t do the reverse. Since I just have a CSV file, I don’t care about formatting or anything like that. I’m not worried if it only generates a very simple XLS file, and doesn’t support the fancy new versions. Just so long as it’s an XLS spreadsheet.

If you rename the file from foo.csv to foo.xls, when you put it on a Windows or Mac OS machine, Excel will open it quite happily. Same thing with html files renamed to foo.doc.

not really, I’ve just tested it (renamed a .csv into .xls) and, while it surely opens in Excel, the cell structure is messed up, or should I say, nonexistent — the cells in the leftmost column contain a line of the .csv file each, — the fields don’t get separated. Not very useful

Was the original .csv well-formatted? Try pasting a snippet of it into the question, as Paul’s original suggestion has worked wonderfully for me in the past (Directive from management to generate Excel reports instead of CSV format — my solution was merely changing the extension of the output file and they were happy 🙂 )

If a csv saved with a .xls extension doesn’t work, you could try a tab separated text file. That’s an easy conversion as long as there are no newlines or tabs in the data.

I need this sort of conversion at my workplace because when I pass people CSV or TSV files, half the time Excel doesn’t properly detect the column separator, or the fact that strings can be quoted, or whatever, and people get confused on what’s going wrong and how to resolve it. It would be a smoother experience if I could just pass people a real XLS file I 100% knew Excel wouldn’t have issues with.

9 Answers 9

Try using the ssconvert tool from «gnumeric» package. On Debian, install the package with sudo apt-get install gnumeric and then from the command-line, run:

ssconvert file.csv file.xls 

ssconvert does not keep your data in the same state as it was going in, and is as such not a utility that should be used unless you are absolutely certain that all fields are quoted etc. Example: a field with a value of 0330 will be converted to ‘330’.

Actually, when I now tested ssconvert again I found that it destroys your data, regardless of quoting, and as such is a tool that in my opinion can not be used at all. Sorry, but downvote from me.

Читайте также:  Astra linux сертификат соответствия фстэк

Yeah, ssconvert is useless for any serious work. I had been using ssconvert a lot until I realized it screws up formatting for any text containing numeric characters. i.e. ditto what Christoper says. This really sucks because otherwise ssconvert is painless.

Why would you want to do that? Since you are not interested in adding or modifying data/metadata, you could just leave it as csv. CSV is associated with MS Excel by default, so whoever is going to open it, is going to get it opened in MS Excel.

If that does not work for you for some reason, keep in mind, that, as far as I know, you can generate a (sort of) valid xls file by using the following skeleton:

  ..  . ad inf
field0 field1fieldX

In Office 2007, I get a warning «The file you are trying to open is in a different format than specified by the file extension. Verify that the file is not corrupted and from a trusted souce before opening the file. Do you want to open the file now?», which probaly isn’t acceptable in many cases.

You wouldn’t want to do this because Excel is terrible at interpreting and formatting CSV files. e.g. It will automatically interpret a numeric text as an integer, even if it’s quoted or 30 characters long, causing it to render in scientific notation.

There is a python based solution on Sourceforge called csv2xls which may fit the bill.

It does not appear to be maintained at the moment (last activity was over a year ago) but if it does what you need then that shouldn’t matter too much.

Try using an Openoffice macro.

See for a start : How to convert Word -> PDF from the command line http://www.oooforum.org/forum/viewtopic.phtml?t=3772

There are indeed some problems with the filters from CSV and any form XLS or even openOffice. Like the: Record separator: , Line terminator: \n or ; String definition: » or the like.

If I get it correctly you want to do it on the command line within some scripts. This is exactly the same problem I have right now: from DATA in csv format, present it to the customer in XLS format.

But I am not totally satisfied. They might be an option.

Indeed if you have some sort of openOffice installed you can try to play with some info from: http://ask.libreoffice.org/en/question/2641/convert-to-command-line-parameter/

And part of the output is:

--convert-to output_file_extension[:output_filter_name] [-outdir ouput_dir] files Batch convert files. If -outdir is not specified then current working dir is used as output_dir. Eg. -convert-to pdf *.doc -convert-to pdf:writer_pdf_Export -outdir /home/user *.doc 

I would write a little code to directly output a simple version of the Excel 2002 XML format: http://en.wikipedia.org/wiki/Microsoft_Excel#File_formats

XML Spreadsheet

Though the intended file extension for this format is .xml, the program also correctly handles XML files with .xls extension. This feature is widely used by third-party applications (e.g. MySQL Query Browser) to offer «export to Excel» capabilities without implementing binary file format. The following example will be correctly opened by Excel if saved either as Book1.xml or Book1.xls:

Alternately, if that didn’t provide enough features, I’d directly implement minimal .xlsx output. It is a zip file with XML files which should be tractable compared to the old binary formats.

Источник

convert CSV to XLS file on linux

The following Perl script can convert CSV file to XLS file the problem is that I need to install on customer Linux machine many Perl modules in order to run this Perl script , and actually I cant because the Linux machine is customer machine ( not allow to install modules ) So I need to find some other alternative for this Perl script First customer have Linux red-hat machine version 5.X And I want to find some bash/ksh/sh/awk scripts that can do the job the same as the perl script do so I want to find other alternative that convert CSV to XLS file Please advice how to find this script? or other advice to convert CSV to XLS on Linux machine

#!/usr/bin/perl -w ############################################################################### # # Example of how to use the WriteExcel module # # Simple program to convert a CSV comma-separated value file to an Excel file. # This is more or less an non-op since Excel can read CSV files. # The program uses Text::CSV_XS to parse the CSV. # # Usage: csv2xls.pl file.csv newfile.xls # # # NOTE: This is only a simple conversion utility for illustrative purposes. # For converting a CSV or Tab separated or any other type of delimited # text file to Excel I recommend the more rigorous csv2xls program that is # part of H.Merijn Brand's Text::CSV_XS module distro. # # See the examples/csv2xls link here: # L # # reverse('©'), March 2001, John McNamara, jmcnamara@cpan.org # use strict; use Spreadsheet::WriteExcel; use Text::CSV_XS; # Check for valid number of arguments if ( ( $#ARGV < 1 ) || ( $#ARGV >2 ) ) < die("Usage: csv2xls csvfile.txt newfile.xls\n"); ># Open the Comma Separated Variable file open( CSVFILE, $ARGV[0] ) or die "$ARGV[0]: $!"; # Create a new Excel workbook my $workbook = Spreadsheet::WriteExcel->new( $ARGV[1] ); my $worksheet = $workbook->add_worksheet(); # Create a new CSV parsing object my $csv = Text::CSV_XS->new; # Row and column are zero indexed my $row = 0; while () < if ( $csv->parse($_) ) < my @Fld = $csv->fields; my $col = 0; foreach my $token (@Fld) < $worksheet->write( $row, $col, $token ); $col++; > $row++; > else < my $err = $csv->error_input; print "Text::CSV_XS parse() failed on argument: ", $err, "\n"; > > 

I am so tempted to give this answer. cheat: rename file.csv to file.xls. excel opens it and you never notice the difference.

Читайте также:  Dos window in linux

@maihabunash, you should either delete the question posted in stack overflow or here. If you have it posted in 2 places, it will get closed.

CSV files (in general) are difficult to parse, you have cell values with newlines, quotes and commas. XLS files (the old ones, not the more modern XLSM xml files) are binary files that are non-trivial to generate.

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Fast and simple opensource command line tool to convert CSV do XLSX

License

mentax/csv2xlsx

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

Читайте также:  Wps для linux русификатор

README.md

An actual version always available by run csv2xlsx -h or csv2xlsx help

csv2xlsx — Convert CSV data to xlsx — especially the big one.

csv with 50k rows, 5 MB, with xlsx template — 5s

csv2xlsx --template example/template.xlsx --sheet Sheet_1 --sheet Sheet_2 --row 2 --output result.xlsx data.csv data2.csv csv2xlsx.exe -t example/template.xlsx -s Sheet_1 -s Sheet_2 -r 2 -o result.xlsx data.csv data2.csv
csv2xlsx [global options] command [command options] [file of file's list with csv data] 
--sheets names, -s names sheet names in the same order like csv files. If sheet with that name exists, data is inserted to this sheet. Usage: -s AA -s BB --template path, -t path path to xlsx file with template output --row number, -r number row number to use for create rows format. When '0' - not used. This row will be removed from xlsx file. (default: 0) --output xlsx file, -o xlsx file path to result xlsx file (default: "./output.xlsx") --help, -h show help --version, -v print the version 

Источник

Convert CSV to Excel or Excel to CSV on Linux using .NET

CSV to Excel or Excel to CSV

CSV files are widely used to store the data in the form of comma-separated values. However, in certain cases, you need to export data from CSV files to Excel spreadsheets or vice versa. For such cases, this article covers how to export data from CSV to Excel and Excel to CSV on Linux.

CSV to Excel or Excel to CSV Converter for Linux#

To export data from CSV to Excel or Excel to CSV, we will use Aspose.Cells for .NET. It is a powerful API for creating and manipulating Excel files from within the .NET applications. You can either download the API or install it via NuGet.

If you are new to .NET development on Linux, read how to create a console application on Linux using Visual Studio Code. For the installation of Aspose.Cells for .NET in your application, you can use the NuGet Package Manager extension for Visual Studio Code.

Convert CSV to Excel XLSX/XLS on Linux#

The following are the steps to convert a CSV file to Excel XLSX/XLS on Linux.

  1. Create an instance of LoadOptions class and specify the input format.
  2. Create an instance of Workbook class and initialize it with CSV file’s path and LoadOptions object.
  3. Convert CSV to Excel using Workbook.Save(string, SaveFormat.Xlsx) method.

The following code sample shows how to convert a CSV file to Excel XLSX.

Convert Excel to CSV on Linux#

The following are the steps to convert an Excel XLSX/XLS file to CSV format.

  1. Create an instance of Workbook class and initialize it with Excel file’s path.
  2. Convert Excel to CSV using Workbook.Save(string, SaveFormat.Csv) method.

The following code sample shows how to convert an Excel XLSX file to CSV.

Get a Free License#

You can use Aspose.Cells for .NET without evaluation limitations using a temporary license.

Conclusion#

In this article, you have learned how to convert CSV files to Excel XLSX/XLS on Linux. Moreover, you have seen how to export data from Excel spreadsheets to CSV files. You can explore more about Aspose.Cells for .NET using the documentation. In case you would have any queries, you can ask us via our forum.

See Also#

Источник

Оцените статью
Adblock
detector