excelsample.java
来自「一个专家资料的管理系统」· Java 代码 · 共 48 行
JAVA
48 行
package cn.com.likai.sms.db;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
public class ExcelSample {
/**
* @param args
*/
public static void main(String[] args) throws IOException{
// TODO Auto-generated method stub
FileInputStream fileln = new FileInputStream("workbook.xls");
POIFSFileSystem fs = new POIFSFileSystem(fileln);
HSSFWorkbook wb = new HSSFWorkbook(fs);
HSSFSheet sheet = wb.getSheetAt(0);
HSSFRow row = sheet.getRow(2);
if(row == null){
System.out.println("fail 1");
return;
}
HSSFCell cell = row.getCell((short)1);
if(cell == null){
System.out.println("fail 2");
return;
}
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("凯哥");
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();
try{
Runtime.getRuntime().exec("cmd /c start \\workbook.xls");
}catch(IOException e){e.printStackTrace();}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?