EXCEL急救,各位老大给个POI设置excel公式的例子吧,在线跪求,高分相报,顶者有分! 如题,顺便问一句jxl2.58能编辑excel公式么? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 做报表,做word,做pdf等等,我都用的另外一个工具,这个没用过帮你顶一下,也学习一下 晕,也不说用什么工具!够狠!JABOC? JXL行不?别等了,自己上网搜搜吧,应该有的。 我想要一些poi或jxl设计excel公式的例子,譬如时间日期,某些行列求和求平均数。如果没有例子告诉我用poi或jxl中哪个包里的那些类也可以,主要是api太多没有时间看。各位帮个忙。分数不够可以补贴加分。 jxl,poi均可。谢谢。听说jxl在update时只是制作一个excel的副本,并没有改变源文件,请问是不是这样啊? 新手不太明白,找一个文章希望能帮上楼主用jxl读excel文件相对比较简单,以下这个函数实现了读excel文件的 的功能。根据传入的excel路径名,sheetid和行编号等读取一列的数据。最后返回给一个arraylist对象。public ArrayList getList(int sheetid, int rowid, int fromrowno,String xlspath) { ArrayList aryList = new ArrayList(); Workbook book = null; try { book = Workbook.getWorkbook(new java.io.File(xlspath)); } catch (BiffException ex) { System.out.println("Read Excel file failed!"); System.out.println("File name: " + xlspath); System.exit(0); } catch (IOException ex) { System.out.println("Read Excel file failed!"); System.out.println("File name: " + xlspath); System.exit(0); } //get sheet object Sheet sheet = book.getSheet(sheetid); String result; int i = 0; int rowcnt = sheet.getRows(); for (i = 0; i < rowcnt - fromrowno; i++) { result = ""; Cell cell = sheet.getCell(rowid, i + fromrowno); result = cell.getContents(); result = result.replace('\\n', ' '); result = result.trim(); if (!result.equals("")) { aryList.add(result); } } book.close(); return aryList; }Jxl在写excel文件时使用的方法比较怪,也可以说jxl不支持修改excel文件。它的处理方式是每次打开旧excel文件,然后创建一个该excel文件的可写的副本,所有的修改都是在这个副本上做的。下面是一个例子。//create a workbook by opening a existing excel file Workbook rw = null; try { rw = Workbook.getWorkbook(new File(strSrcFile)); } catch (BiffException ex) { System.out.println("Open template Excel file failed!"); System.out.println("File name: "+strSrcFile); CommonTool.log.warning("Open template Excel file failed! file name: " + strSrcFile); System.exit(0); } catch (IOException ex) { System.out.println("Open template Excel file failed!"); System.out.println("File name: "+strSrcFile); CommonTool.log.warning("Open template Excel file failed! file name: " + strSrcFile); System.exit(0); }//create a writable workbook by copying the old one FileOutputStream fstream = null; try { fstream = new FileOutputStream(strFile); } catch (FileNotFoundException ex1) { System.out.println("Create result Excel file failed!"); System.out.println("File name: "+strFile); CommonTool.log.warning("Create result Excel file failed! file name: " + strFile); System.exit(0); } try { WritableWorkbook book = Workbook.createWorkbook(fstream, rw, new WorkbookSettings()); } catch (IOException ex2) { System.out.println("Create result Excel file failed! Copy step"); System.out.println("File name: "+strFile); CommonTool.log.warning("Create result Excel file failed! file name: " + strFile); System.exit(0); } try { WritableCellFormat format = new WritableCellFormat(); format.setBorder(Border.ALL, BorderLineStyle.THIN);//1: rowid; 2 column id jxl.write.Label label = new jxl.write.Label(1, 2, "test", format); book.addCell(label); } catch (WriteException ex) { System.out.println("Add cell failed!"); System.out.println("Cell: "+str); System.exit(0); }最后一个建议就是尽量使用新版本的jxl. 谢谢楼上,我只是想要个poi或jxl设置excel公式 的例子譬如,求和,平均数,日期之类的。 public class TestConfigSumFormula { public static void main(String args[]) { WritableWorkbook book = null; try { //Excel获得文件 Workbook wb = Workbook.getWorkbook(new File("测试.xls")); //打开一个文件的副本,并且指定数据写回到原文件 book = Workbook.createWorkbook(new File("测试.xls"), wb); //添加一个工作表 WritableSheet sheet = book.getSheet("第一页"); FormulaRecord form=new FormulaRecord(0,1,"(A1+B1)*C1/D1"); sheet.addCell(form); book.write(); } catch (IOException ioe) { ioe.printStackTrace(); } catch (BiffException be) { be.printStackTrace(); } catch (WriteException we) { we.printStackTrace(); } finally { try { if (book != null) { book.close(); } } catch (IOException ioe) { ioe.printStackTrace(); } catch (WriteException we) { we.printStackTrace(); } } }}其中公式我只试过SUM(A1:D1),AVERAGE(A1:B1),TODAY()好像只能返回一个毫秒数。 JTable的问题········急急急急急急急急急急急急急急!!!!! 请问各位大虾,如何在dataInputSteam流写入数据后对写入数据的文件数据内容进行更改? 如何操作JFreeChart生成的图? 如何更新ResultSet的列!? 设置环境变量问题(菜,不要BS,汗-_-!!) java的内存运作如何 import后有问题 关于java的一个简单问题 Session可以传送数组吗? JDBC空指针异常,求帮助!(40分) 类/变量动态访问的问题 我是个Java新手,请高手们帮忙看看这个程序运行结果为什么不对??
用jxl读excel文件相对比较简单,以下这个函数实现了读excel文件的 的功能。根据传入的excel路径名,sheetid和行编号等读取一列的数据。最后返回给一个arraylist对象。public ArrayList getList(int sheetid, int rowid, int fromrowno,String xlspath) {
ArrayList aryList = new ArrayList();
Workbook book = null;
try {
book =
Workbook.getWorkbook(new java.io.File(xlspath));
}
catch (BiffException ex) {
System.out.println("Read Excel file failed!");
System.out.println("File name: " + xlspath);
System.exit(0); }
catch (IOException ex) {
System.out.println("Read Excel file failed!");
System.out.println("File name: " + xlspath);
System.exit(0); } //get sheet object
Sheet sheet = book.getSheet(sheetid);
String result;
int i = 0;
int rowcnt = sheet.getRows();
for (i = 0; i < rowcnt - fromrowno; i++) {
result = "";
Cell cell = sheet.getCell(rowid, i + fromrowno);
result = cell.getContents();
result = result.replace('\\n', ' ');
result = result.trim();
if (!result.equals("")) {
aryList.add(result);
}
}
book.close();
return aryList;
}Jxl在写excel文件时使用的方法比较怪,也可以说jxl不支持修改excel文件。它的处理方式是每次打开旧excel文件,然后创建一个该excel文件的可写的副本,所有的修改都是在这个副本上做的。下面是一个例子。//create a workbook by opening a existing excel file
Workbook rw = null;
try {
rw = Workbook.getWorkbook(new File(strSrcFile));
}
catch (BiffException ex) {
System.out.println("Open template Excel file failed!");
System.out.println("File name: "+strSrcFile);
CommonTool.log.warning("Open template Excel file failed! file name: " + strSrcFile);
System.exit(0);
}
catch (IOException ex) {
System.out.println("Open template Excel file failed!");
System.out.println("File name: "+strSrcFile);
CommonTool.log.warning("Open template Excel file failed! file name: " + strSrcFile);
System.exit(0);
}
//create a writable workbook by copying the old one
FileOutputStream fstream = null;
try {
fstream = new FileOutputStream(strFile);
}
catch (FileNotFoundException ex1) {
System.out.println("Create result Excel file failed!");
System.out.println("File name: "+strFile);
CommonTool.log.warning("Create result Excel file failed! file name: " + strFile);
System.exit(0);
}
try {
WritableWorkbook book =
Workbook.createWorkbook(fstream, rw, new WorkbookSettings());
}
catch (IOException ex2) {
System.out.println("Create result Excel file failed! Copy step");
System.out.println("File name: "+strFile);
CommonTool.log.warning("Create result Excel file failed! file name: " + strFile);
System.exit(0);
}
try {
WritableCellFormat format = new WritableCellFormat();
format.setBorder(Border.ALL, BorderLineStyle.THIN);//1: rowid; 2 column id
jxl.write.Label label = new jxl.write.Label(1, 2, "test", format);
book.addCell(label);
}
catch (WriteException ex) {
System.out.println("Add cell failed!");
System.out.println("Cell: "+str);
System.exit(0);
}
最后一个建议就是尽量使用新版本的jxl.
public static void main(String args[]) { WritableWorkbook book = null; try {
//Excel获得文件
Workbook wb = Workbook.getWorkbook(new File("测试.xls")); //打开一个文件的副本,并且指定数据写回到原文件
book = Workbook.createWorkbook(new File("测试.xls"), wb); //添加一个工作表
WritableSheet sheet = book.getSheet("第一页");
FormulaRecord form=new FormulaRecord(0,1,"(A1+B1)*C1/D1");
sheet.addCell(form); book.write();
}
catch (IOException ioe) {
ioe.printStackTrace();
}
catch (BiffException be) {
be.printStackTrace();
}
catch (WriteException we) {
we.printStackTrace();
}
finally { try {
if (book != null) {
book.close();
}
}
catch (IOException ioe) {
ioe.printStackTrace();
}
catch (WriteException we) {
we.printStackTrace();
}
}
}
}其中公式我只试过SUM(A1:D1),AVERAGE(A1:B1),TODAY()好像只能返回一个毫秒数。