2

Is there a programmatic solution to this that does not involve having Office on the server?

Update: This solution will be deployed in a .Net shop, so for now PHP and Java approaches aren't on the table (though I was impressed with the libraries themselves).

We will be receiving documents in csv, .xls, and .xlsx formats that need to be parsed and their data shoved into a DB. We're planning on using the OpenXML SDK for all of the parsing goodness and want to operate over only one file type.

KevDog
  • 5,763
  • 9
  • 42
  • 73
  • 1
    Do these questions help you? http://stackoverflow.com/questions/1486256/creating-excel-or-excel-compatible-spreadsheets-on-the-server-side-in-c http://stackoverflow.com/questions/1642702/generating-nicely-formatted-excel-files-in-asp-net-without-having-excel-on-server – Richard Morgan May 14 '10 at 19:37
  • Best answer depends on the programming language intend to use or are familiar with. I'd mention them as well. It may also help of you tell a bit more about the context. Is it a client application? Swing? Or a webapplication? JSP/Servlet or PHP? Etc. – BalusC May 15 '10 at 17:50

4 Answers4

3

You can achieve this using the Apache POI library for Java.

HSSF is the POI Project's pure Java implementation of the Excel '97(-2007) file format.

XSSF is the POI Project's pure Java implementation of the Excel 2007 OOXML (.xlsx) file format.

I've used it to read in a complete mix of .xls and .xlsx files, and I always output .xlsx.

For .csv files, import using the Super CSV library and export using the Apache POI library above.

The main motivation for Super Csv is to be the best, fastest and most programmer friendly free CSV package for Java.

Community
  • 1
  • 1
Dolph
  • 49,714
  • 13
  • 63
  • 88
2

Or use PHPExcel ( http://www.phpexcel.net ) if you want a PHP solution rather than java

Mark Baker
  • 209,507
  • 32
  • 346
  • 385
1

For csv files i would recommend a combination of http://kbcsv.codeplex.com/ to read the csv file into a datatable and EPPPLUS to use its .FromDataTable Method to convert it to an xlsx file. I works great for me and is very fast. For reading xls files there is no free Implementation that I know of :(

Christian Sauer
  • 10,351
  • 10
  • 53
  • 85
0

and you can use for parse columns.

 object columnValue = ws.Cells[i, ColIndex, i, ColIndex].Value; // get Specific cell.  

you can use below method for .csv, xlsx, .txt files.

      public yourReturnType compute()
        {
            #region .XLSX Section

            if (FilePath.FullName.Contains(".xlsx") || FilePath.FullName.Contains(".xls"))
            {
                // Open and read the XlSX file.
                using (var package = new ExcelPackage(FilePath))
                {
                    ExcelWorkbook wb = package.Workbook;  // Get the work book in the file
                    if (wb != null)
                    {
                        if (wb.Worksheets.Count > 0)
                        {
                            ExcelWorksheet ws = wb.Worksheets.First();  // Get the first worksheet

                              yourParseCode(ws);
                        }
                    } // if End.
                } // using end.
            }
            #endregion

            #region .CSV Section
            if (FilePath.FullName.Contains(".csv") || FilePath.FullName.Contains(".txt"))
            {
                CSVParser c = new CSVParser(FilePath);
                DataTable dt = c.ReadCSVFile();

                using (ExcelPackage pck = new ExcelPackage())
                {
                    ExcelWorksheet ws = pck.Workbook.Worksheets.Add("temporary");
                    ws.Cells["A1"].LoadFromDataTable(dt, true);

                    yourParseCode (ws);

                    ////pck.Save(); // no need to save this temporary sheet.
                }
            }
            #endregion
            return (yourReturnType );
        }
Muhammad Mubashir
  • 1,591
  • 1
  • 21
  • 18