Is there a programmatic solution to this that does not involve having Office on the server?
是否有一个程序化的解决方案,不涉及在服务器上安装Office?
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).
更新:此解决方案将部署在.Net商店中,因此目前还没有PHP和Java方法(虽然我对库本身印象深刻)。
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.
我们将接收需要解析的csv,.xls和.xlsx格式的文档,并将其数据推送到数据库中。我们计划将OpenXML SDK用于所有解析优势,并且只想在一种文件类型上运行。
4 个解决方案
#1
3
You can achieve this using the Apache POI library for Java.
您可以使用Apache POI库Java实现此目的。
HSSF is the POI Project's pure Java implementation of the Excel '97(-2007) file format.
HSSF是POI项目的Excel '97(-2007)文件格式的纯Java实现。
XSSF is the POI Project's pure Java implementation of the Excel 2007 OOXML (.xlsx) file format.
XSSF是POI Project的Excel 2007 OOXML(.xlsx)文件格式的纯Java实现。
I've used it to read in a complete mix of .xls
and .xlsx
files, and I always output .xlsx
.
我用它来读取完整的.xls和.xlsx文件,我总是输出.xlsx。
For .csv
files, import using the Super CSV library and export using the Apache POI library above.
对于.csv文件,使用Super CSV库导入并使用上面的Apache POI库导出。
The main motivation for Super Csv is to be the best, fastest and most programmer friendly free CSV package for Java.
Super Csv的主要动机是成为最好,最快,程序最友好的Java免费CSV包。
#2
2
Or use PHPExcel ( http://www.phpexcel.net ) if you want a PHP solution rather than java
或者如果你想要PHP解决方案而不是java,请使用PHPExcel(http://www.phpexcel.net)
#3
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 :(
对于csv文件,我建议组合使用http://kbcsv.codeplex.com/将csv文件读入数据表和EPPPLUS,以使用其.FromDataTable方法将其转换为xlsx文件。我对我很好,而且速度非常快。对于阅读xls文件,没有我知道的免费实现:(
#4
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.
您可以使用以下方法来处理.csv,xlsx,.txt文件。
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 );
}
#1
3
You can achieve this using the Apache POI library for Java.
您可以使用Apache POI库Java实现此目的。
HSSF is the POI Project's pure Java implementation of the Excel '97(-2007) file format.
HSSF是POI项目的Excel '97(-2007)文件格式的纯Java实现。
XSSF is the POI Project's pure Java implementation of the Excel 2007 OOXML (.xlsx) file format.
XSSF是POI Project的Excel 2007 OOXML(.xlsx)文件格式的纯Java实现。
I've used it to read in a complete mix of .xls
and .xlsx
files, and I always output .xlsx
.
我用它来读取完整的.xls和.xlsx文件,我总是输出.xlsx。
For .csv
files, import using the Super CSV library and export using the Apache POI library above.
对于.csv文件,使用Super CSV库导入并使用上面的Apache POI库导出。
The main motivation for Super Csv is to be the best, fastest and most programmer friendly free CSV package for Java.
Super Csv的主要动机是成为最好,最快,程序最友好的Java免费CSV包。
#2
2
Or use PHPExcel ( http://www.phpexcel.net ) if you want a PHP solution rather than java
或者如果你想要PHP解决方案而不是java,请使用PHPExcel(http://www.phpexcel.net)
#3
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 :(
对于csv文件,我建议组合使用http://kbcsv.codeplex.com/将csv文件读入数据表和EPPPLUS,以使用其.FromDataTable方法将其转换为xlsx文件。我对我很好,而且速度非常快。对于阅读xls文件,没有我知道的免费实现:(
#4
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.
您可以使用以下方法来处理.csv,xlsx,.txt文件。
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 );
}