java中怎么样修改excel? 有,不过没在手头放着,jdbc+odbc连的话,也不用想具体是excel还是sqlserver,拿来用就好了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 有专门操作excl的jar包,找一下,很好用的。java 对excl的操作不是很难 poi 和jex吧....有开源的包的............................ 用poi,这是我的一个例子,如果要修改,可先用fs = new POIFSFileSystem(new FileInputStream("d:/workbook.xls")); wb = new HSSFWorkbook(fs); 读入,修改后再用FileOutputStream fileOut = new FileOutputStream("d:/workbook.xls");wb.write(fileOut);回写import org.apache.poi.hssf.usermodel.*;import java.io.*;import java.util.*;import org.apache.poi.poifs.filesystem.POIFSFileSystem; public class exceltest {public static void writeexcel() throws IOException {HSSFWorkbook wb = new HSSFWorkbook();//建立新HSSFWorkbook对象HSSFSheet sheet = wb.createSheet("new sheet");//建立新的sheet对象 0 开始HSSFRow row = sheet.createRow((short)0);//建立新行HSSFCell cell = row.createCell((short)0);//建立新cellcell.setCellValue(3.3);//设置cell的整数类型的值row.createCell((short)1).setCellValue(1.2);//设置cell浮点类型的值row.createCell((short)2).setCellValue("test");//设置cell字符类型的值row.createCell((short)3).setCellValue(true);//设置cell布尔类型的值 HSSFCellStyle cellStyle = wb.createCellStyle();//建立新的cell样式cellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy h:mm"));//设置cell样式为定制的日期格式HSSFCell dCell =row.createCell((short)4);dCell.setCellValue(new Date());//设置cell为日期类型的值dCell.setCellStyle(cellStyle); //设置该cell日期的显示格式HSSFCell csCell =row.createCell((short)5);csCell.setEncoding(HSSFCell.ENCODING_UTF_16);//设置cell编码解决中文高位字节截断csCell.setCellValue("中文测试_Chinese Words Test");//设置中西文结合字符串row.createCell((short)6).setCellType(HSSFCell.CELL_TYPE_ERROR);//建立错误cellFileOutputStream fileOut = new FileOutputStream("d:/workbook.xls");wb.write(fileOut);fileOut.close();System.out.println("hahaha");} public static void readexcel() { POIFSFileSystem fs = null; HSSFWorkbook wb = null; try { fs = new POIFSFileSystem(new FileInputStream("d:/workbook.xls")); wb = new HSSFWorkbook(fs); } catch (IOException e) { e.printStackTrace(); } HSSFSheet sheet = wb.getSheetAt(0); HSSFRow row = sheet.getRow(0); HSSFCell cell = row.getCell((short)0); double msg = cell.getNumericCellValue(); System.out.println(msg); // String msg1 = cell.getCellFormula(); // System.out.println(msg1); } public static void main(String[] args) throws IOException {writeexcel(); System.out.println("Write OK"); readexcel(); System.out.println("Read OK"); } 用jxl 或者可以直接把excel当成数据库那样连接 用SSH怎样实现论坛发帖功能??? java变量 Struts2示例项目中的一个有关通配符匹配的问题 jboss+oracle配置问题 大虾们帮小女子看看这问题 !!! 急!!!! 数据库查询的问题,请教 初学ANT,请教了 请推荐一些基于struts模式开发的网站的源代码例子? ***禁止重复登录?*** cmpbean的问题 请教高手!根据xml文档的属性查找一个节点??可以实现吗 hibernate3.1 reference 中的例子问题
java 对excl的操作不是很难
fs = new POIFSFileSystem(new FileInputStream("d:/workbook.xls"));
wb = new HSSFWorkbook(fs);
读入,修改后再用
FileOutputStream fileOut =
new FileOutputStream("d:/workbook.xls");
wb.write(fileOut);
回写
import org.apache.poi.hssf.usermodel.*;
import java.io.*;
import java.util.*;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
public class exceltest {public static void writeexcel() throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
//建立新HSSFWorkbook对象
HSSFSheet sheet = wb.createSheet("new sheet");
//建立新的sheet对象 0 开始
HSSFRow row = sheet.createRow((short)0);
//建立新行
HSSFCell cell = row.createCell((short)0);
//建立新cell
cell.setCellValue(3.3);//设置cell的整数类型的值
row.createCell((short)1).setCellValue(1.2);
//设置cell浮点类型的值
row.createCell((short)2).setCellValue("test");
//设置cell字符类型的值
row.createCell((short)3).setCellValue(true);
//设置cell布尔类型的值
HSSFCellStyle cellStyle = wb.createCellStyle();
//建立新的cell样式
cellStyle.setDataFormat
(HSSFDataFormat.getBuiltinFormat("m/d/yy h:mm"));
//设置cell样式为定制的日期格式
HSSFCell dCell =row.createCell((short)4);
dCell.setCellValue(new Date());
//设置cell为日期类型的值
dCell.setCellStyle(cellStyle);
//设置该cell日期的显示格式
HSSFCell csCell =row.createCell((short)5);
csCell.setEncoding(HSSFCell.ENCODING_UTF_16);
//设置cell编码解决中文高位字节截断
csCell.setCellValue("中文测试_Chinese Words Test");
//设置中西文结合字符串
row.createCell((short)6).setCellType
(HSSFCell.CELL_TYPE_ERROR);
//建立错误cell
FileOutputStream fileOut =
new FileOutputStream("d:/workbook.xls");
wb.write(fileOut);
fileOut.close();
System.out.println("hahaha");
}
public static void readexcel() {
POIFSFileSystem fs = null;
HSSFWorkbook wb = null;
try {
fs = new POIFSFileSystem(new FileInputStream("d:/workbook.xls"));
wb = new HSSFWorkbook(fs);
} catch (IOException e) {
e.printStackTrace();
}
HSSFSheet sheet = wb.getSheetAt(0);
HSSFRow row = sheet.getRow(0);
HSSFCell cell = row.getCell((short)0);
double msg = cell.getNumericCellValue();
System.out.println(msg);
// String msg1 = cell.getCellFormula();
// System.out.println(msg1);
}
public static void main(String[] args) throws IOException {
writeexcel();
System.out.println("Write OK");
readexcel();
System.out.println("Read OK");
}