java POI Excel API 到底需要什么
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17805781/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What exactly does need for POI Excel API
提问by dskim
I'm working on program that make Excel data via POI API 3.9 .
我正在开发通过 POI API 3.9 制作 Excel 数据的程序。
but there are many Jar files in directory as follows.
但是目录中有很多Jar文件如下。
poi-3.9-20121203
poi-excelant-3.9-20121203
poi-ooxml-3.9-20121203
poi-ooxml-schemas-3.9-20121203
poi-scratchpad-3.9-20121203
ooxml-lib/xmlbeans-2.3.0
lib/commons-logging-1.1
..etc.
I just need creating, reading and writing excel files . i'm confused what jar files is need.
我只需要创建、读取和写入 excel 文件。我很困惑需要什么 jar 文件。
please tell me what files i got to import. I have read many domcuments on website . But i'can find it about that.
请告诉我要导入哪些文件。我在网站上阅读了很多文档。但我可以找到它。
Thank you
谢谢
回答by Erik Pragt
Don't worry about your dependencies too much in your case. Just use a tool like Mavenor Gradle, and add the POI dependency:
在您的情况下,不要过分担心您的依赖项。只需使用像Maven或Gradle这样的工具,并添加POI 依赖项:
Maven:
马文:
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.9</version>
</dependency>
Gradle
摇篮
'org.apache.poi:poi:3.9'
This will give you the right dependencies.
这将为您提供正确的依赖项。
回答by LaurentG
You probably have to import all of them. As many frameworks, Apache POI is splitted in different libraries. Apache POI also uses external libraries like XML Beans.
您可能必须导入所有这些。与许多框架一样,Apache POI 分为不同的库。Apache POI 还使用外部库,如 XML Beans。
On the Apache POI website, you will find the list of components and for which goal there are needed, look at the Component Mapsection.
在Apache POI 网站 上,您将找到组件列表以及需要哪些目标,请查看组件地图部分。
Typically if you are handling only old Excel files, you don't need the poi-ooxml
dependency.
通常,如果您只处理旧的 Excel 文件,则不需要poi-ooxml
依赖项。
Note that your list of external dependencies is listed in the Prerequisitescolumn of the second table of the Component Map section, as described there you also need additional libraries: commons-logging
, commons-codec
, log4j
.
请注意,您的外部依赖项列表列在组件映射部分第二个表的先决条件列中,如此处所述,您还需要其他库:commons-logging
, commons-codec
, log4j
.
Finally, to avoid headaches with dependency management, you could use a tool like Maven which cares of this for you.
最后,为了避免依赖管理带来的麻烦,您可以使用像 Maven 这样的工具来为您解决这个问题。
回答by Sankumarsingh
You need just 5 jars for your mentioned tasks
您只需要 5 个罐子即可完成您提到的任务
for example if we are using apache 3.9
例如,如果我们使用 apache 3.9
dom4j-1.6.1.jar
poi-3.9-20121203.jar
poi-ooxml-3.9-0121203.jar
poi-ooxml-schemas-3.9-0121203.jar
xmlbeans-2.3.0.jar
回答by MD Sayem Ahmed
If you use Maven for project build, then you can simply add the following two dependencies on your project -
如果您使用 Maven 进行项目构建,那么您可以简单地在您的项目中添加以下两个依赖项 -
<!-- Apache POI -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.9</version>
</dependency>
This will download all the required jars for you.
这将为您下载所有必需的 jar。
Hereis a demo project that I've developed demonstrating the excel reading approach. The above lines are taken from my project pom. This approach works just fine for me.
这是我开发的一个演示项目,用于展示 excel 阅读方法。以上几行摘自我的项目 pom。这种方法对我来说效果很好。
回答by Amitabh Ranjan
(1)Hi, here I am posting a link where you will get all the information related to your question.
(1)您好,我在这里发布一个链接,您将在其中获得与您的问题相关的所有信息。
http://selenium-testng.com/test-data-through-excel/
http://selenium-testng.com/test-data-through-excel/
(2)You can download all the required jars from this URL
(2)你可以从这个网址下载所有需要的jar包
http://poi.apache.org/download.html
http://poi.apache.org/download.html
(3)extract the URL and include all the jars in your classPath
(3) 提取 URL 并将所有 jars 包含在您的 classPath 中
(4)For MS Excel Examples you can check the following sites. It has all the examples required.
(4) 对于 MS Excel 示例,您可以查看以下站点。它具有所需的所有示例。
回答by Huy Hóm H?nh
You can use ver 3.9 or ver 3.8 instead. But I find that poi ver.3.9 remove some class(org.apache.poi.xssf.usermodel.XSSFWorkbook for example) which till provides on poi-3.8-20120326.jar. So verify if those class used on your project.
您可以改用 3.9 版或 3.8 版。但我发现 poi ver.3.9 删除了一些类(例如 org.apache.poi.xssf.usermodel.XSSFWorkbook),直到在 poi-3.8-20120326.jar 上提供。因此,请验证您的项目中是否使用了这些类。
Hope this help!
希望这有帮助!
回答by gauravsngarg
Thanks to the below link
感谢以下链接
http://www.mysamplecode.com/2011/10/android-read-write-excel-file-using.html
http://www.mysamplecode.com/2011/10/android-read-write-excel-file-using.html
Worked for me :)
对我来说有效:)
Working Edited Code:
工作编辑代码:
public static boolean isExternalStorageReadOnly() {
String extStorageState = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(extStorageState)) {
return true;
}
return false;
}
public static boolean isExternalStorageAvailable() {
String extStorageState = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(extStorageState)) {
return true;
}
return false;
}
private static boolean saveExcelFile(MainActivity mainActivity, String fileName) {
// check if available and not read only
if (!isExternalStorageAvailable() || isExternalStorageReadOnly()) {
Log.w("FileUtils", "Storage not available or read only");
return false;
}
boolean success = false;
//New Workbook
Workbook wb = new HSSFWorkbook();
Cell c = null;
//Cell style for header row
CellStyle cs = wb.createCellStyle();
cs.setFillForegroundColor(HSSFColor.LIME.index);
cs.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
//New Sheet
Sheet sheet1 = null;
sheet1 = wb.createSheet("Sheet1");
// Generate column headings
Row row = sheet1.createRow(0);
c = row.createCell(0);
c.setCellValue(DBHelper.INVENTORY_PROJECT_CODE);
c.setCellStyle(cs);
c = row.createCell(1);
c.setCellValue(DBHelper.INVENTORY_PROJECT_UPC_BAR_CODE);
c.setCellStyle(cs);
c = row.createCell(2);
c.setCellValue(DBHelper.INVENTORY_PROJECT_NAME);
c.setCellStyle(cs);
c = row.createCell(3);
c.setCellValue(DBHelper.INVENTORY_PROJECT_QUANTITY);
c.setCellStyle(cs);
c = row.createCell(4);
c.setCellValue(DBHelper.INVENTORY_PROJECT_PRICE);
c.setCellStyle(cs);
ArrayList<String> arrayList1 = dbHelper.getAllRecords();
int rowno = 1;
int columnno=0;
for(String red : arrayList1){
columnno = 0;
Row row1 = sheet1.createRow(rowno);
String[] parts = red.split(Pattern.quote(","));
for(String str : parts){
c = row1.createCell(columnno);
c.setCellValue(str);
c.setCellStyle(cs);
columnno++;
}
rowno++;
}
sheet1.setColumnWidth(0, (15 * 500));
sheet1.setColumnWidth(1, (15 * 500));
sheet1.setColumnWidth(2, (15 * 500));
sheet1.setColumnWidth(3, (15 * 500));
sheet1.setColumnWidth(4, (15 * 500));
// Create a path where we will place our List of objects on external storage
File file = new File(mainActivity.getExternalFilesDir(null), fileName);
FileOutputStream os = null;
try {
os = new FileOutputStream(file);
wb.write(os);
Log.w("FileUtils", "Writing file" + file);
success = true;
} catch (IOException e) {
Log.w("FileUtils", "Error writing " + file, e);
} catch (Exception e) {
Log.w("FileUtils", "Failed to save file", e);
} finally {
try {
if (null != os)
os.close();
} catch (Exception ex) {
}
}
return success;
}
回答by Veera
For standalone project you need the below jars.
对于独立项目,您需要以下 jars。
commons-logging-1.1.jar
commons-logging-1.1.jar
dom4j-1.6.1.jar
dom4j-1.6.1.jar
jsr173_1.0_api.jar
jsr173_1.0_api.jar
log4j-1.2.13.jar
log4j-1.2.13.jar
poi-3.8-20120326.jar
poi-3.8-20120326.jar
poi-ooxml-3.8-20120326.jar
poi-ooxml-3.8-20120326.jar
poi-ooxml-schemas-3.8-20120326.jar
poi-ooxml-schemas-3.8-20120326.jar
resolver.jar
解析器.jar
xbean_xpath.jar
xbean_xpath.jar
xbean.jar
xbean.jar
xmlbeans-qname.jar
xmlbeans-qname.jar
xmlpublic.jar
xml公共文件