How To Change Csv To Xlsx Converter

Active8 months ago

I want my application to go and find a csv excel file and convert it into a .xlsx file instead.

The xlsx format is the default filename extension for all spreadsheet documents produced using Microsoft Office Excel 2007 SP2 and above. Csv Comma Separated Values File The comma-separated values file format or CSV for short is a common cross platform file format used for information exchange between disparate devices, systems, and software. Feb 26, 2014  Just like converting an XLSX to a CSV, you can convert a CSV to XLSX by using the Save As function. Except, instead of looking for CSV (comma delimited), you want to look for Excel Workbook. This will convert it to the familiar XLSX extension. Remember that before 2003, Excel workbooks are.XLS and not.XLSX.

Here's what I'm currently doing;

Now this does work. It changes the file extension to my desired format. However, the file then become 'corrupt' or at least Excel refuses to open it and neither will my application when I try to venture further.

Does anyone have a solution/work-around?

Abhishek
2,3021 gold badge24 silver badges51 bronze badges
WilliamWilliam
2,8378 gold badges27 silver badges53 bronze badges

6 Answers

I would parse in the CSV file and use this to write out an Excel file : https://github.com/JanKallman/EPPlus

Magnetron
3,2141 gold badge10 silver badges23 bronze badges
Mark RedmanMark Redman
16.8k17 gold badges81 silver badges125 bronze badges

For those who want to use Interop instead of an external library, you can simply do this:

The second argument of Workbook.SaveAs determines the true format of the file. You should make the filename extension match that format so Excel doesn't complain about corruption. You can see a list of the types and what they mean on MSDN.

As always, please keep Microsoft's considerations in mind if this functionality is intended for a server environment. Download full movie i hate love story in hd. Interop may not be the way to go in that situation:

Rakuen42Rakuen42

This code should open the file you want and save it to the format without corrupting it.

  1. Renames the file
  2. Creates the Excel.Application instance
  3. Opens the file
  4. Does a save as to the desired format
  5. Closes it

Ben Black
2,8582 gold badges17 silver badges42 bronze badges
arasharash

I would recommend using the following technique:

  1. http://kbcsv.codeplex.com/ this reads CSV files in very easily and is very robust.
  2. Create a datatable from the csv via the kbcsv extensions.
  3. Use the eppplus library and its LoadFromDataTable to create a valid xlsx file (https://github.com/JanKallman/EPPlus)
  4. done!

Advantages:

  • It is faster than excel interop
  • KBCSV is more robust than excels csv reading methods.
  • It is availabe in environments witohout office.
Magnetron
3,2141 gold badge10 silver badges23 bronze badges
Christian SauerChristian Sauer
5,8445 gold badges29 silver badges60 bronze badges

Try this class; takes in any CSV or TXT file with any delimiter including a tab and converts to Excel (.xls)

examples:

  • convertToExcel(@'path to file', 't', '.csv');
  • convertToExcel(@'path to file', '|', '.txt');

costsoldiercostsoldier

I would recommend Closed XML which is a wrapper around Open XML SDK. Check out their examples. It's pretty easy to create a .xlsx file.

cvramancvraman
1,5591 gold badge11 silver badges15 bronze badges

Not the answer you're looking for? Browse other questions tagged c#winforms or ask your own question.

Active3 years, 8 months ago

I am looking for a way to quickly convert a directory of .csv files into the .xls or .xlsx format (would be nice if I could do either/or).

Is there an easy way to do this or do I need to install a third party program?

The poles produce sufficiently strong magnetic flux. Therefore electric power is produced in the stator winding. Since the poles are rotating, the magnetic field is also rotating. Construction and working principle of diesel generator pdf online pdf. The armature windings in the stator windings cut the flux of the rotating poles.

Batchmindless.pandamindless.panda
4,9929 gold badges40 silver badges65 bronze badges

5 Answers

Assuming you like and have Python (for some reason), you could use this script I whipped up:

Ran in the directory with all the CSV files, it will convert them all and slap a '.xls' onto the end.

For Excel 2007+ (xlsx files) supporting up to about 1 Mrows:

Nick TNick T
1,7424 gold badges26 silver badges38 bronze badges

Here is a perl script that supposedly does it, but it does seem like a lot of work to do something that is already built into Excel.

KirkKirk

There is a lot left unsaid in your question.

Assuming that your CVS files are in a directory structure similar to

and you want to end up with

I can think of three routes to go depending on the ratio of upfront work to clean-up work you are willing to do.

  1. No Precoding: Use Windows Explorer to navigate to the CSV files use whatever method works best to select the files to be converted (lasso, ctrl+a, ctrl+click, shift+click) then right click one of the selected files and click on Open. This will open all the files in Excel. Then for each file you can select 'File' and 'Save as' and finally choose the new file format you want it saved to.
  2. A Simple Batch File: That batch file could use wild cards and/or a for each loop structure to open each of the CSV files for you and then you could manually process them as before.
  3. Create a VBA program within an Excel Spreadsheet: VBA could automatically opens each CSV file and then saves it to an Excel format. You could even add a simple message box that offers a choice of either xls or xlsx as each file is opened.

Note that I haven't written any code to do these things (yet) I am just offering ideas for a starting point. Perhaps if you could give more details about what you want you could get more detailed explanations for how to handle approach from me or another forum member.

TedNewkTedNewk

For Windows? CoolUtils 'Total CSV Converter' command line version supports many output formats including JSON, Access, DBF, XML & SQL and is only $40. It can recurse sub-directories, delete original CSV files, combine all files to one document, and more.

'Advanced CSV Converter' ($40-200) is a portable EXE that can do it quickly and without Excel having to be installed.

SoftInterface's 'Convert XLS' can use Excel (but is not required) and is more expensive ($500+), but supports more formats and has more options.

'Gnumeric' is an open-source spreadsheet program that can perform a direct conversion, but it was discontinued for Windows in Aug 2014.

If you have Python installed, 'csv2odf' is a open-source option and uses a templated approach to generate ods, odt, html, xlsx, or docx files.

Repair mov files osx on pc. During this time, you can rely on Remo Repair MOV Mac in order to repair MOV on Windows after it gets corrupt or damaged. By making use of this productive and reliable software, you will be able to resolve all the corruption errors on the video and later on repairing MOV file Windows it reproduces the file to its original clarity. MP4 video files which refuse to play on Mac OS X due to any reason will be repaired easily and made playable by Remo Repair MOV tool. Fix MP4 Video on Mac Quickly repair MP4 video files which fail to play on Mac due to corruption or damage by using Remo MOV Repair software. How to Repair Corrupt MP4 and MOV File using VLC and other Media Player Sumona Chatterjee Updated on January 16, 2019 Video Repair 100 Comments Summary: The post explains the various processes to deal with inaccessible, corrupt MP4 and MOV media files using VLC integrated features and also suggests using a professional Video Repair tool to.

How To Change Csv File Into Bar Chart

user326177user326177

The Easy way: open your csv file from Microsoft Excel, convert text to columns (select the cells/text, click Menu - Data - Text to Columns) set your option to convert.

How To Convert Csv File To Excel

elaifelaif

How To Change Csv Files To Regular Excel

Not the answer you're looking for? Browse other questions tagged microsoft-excelconversion or ask your own question.

Comments are closed.