📄 excelsample.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -