怎么实现通过excel模板里面的名字给excel赋值
下面的是我通过行与列赋值代码.太麻烦.
String templeFile = path + "/common/example/staffresume.xls";
String outputPath = path + "/common";
// テンポレトを取得
// 新規Workbook
HSSFWorkbook hb = null;
try {
POIFSFileSystem pfs = new POIFSFileSystem(new FileInputStream(templeFile));
hb = new HSSFWorkbook(pfs);
} catch (FileNotFoundException e1) {
e1.printStackTrace();
System.out.println("THE FileNotFoundException ERROR,156 lines in the StaffResumeAction");
} catch (IOException e1) {
System.out.println("THE IOException ERROR,159 lines in the system");
e1.printStackTrace();
}
HSSFSheet sheet = hb.getSheetAt(0);
HSSFRow row = null;
HSSFCell cell = null;
/** 姓 名 **/
row = sheet.getRow(4);
cell = row.getCell(7);
if (staff.getStaffName() == null) {
cell.setCellValue(new HSSFRichTextString(""));
} else {
cell.setCellValue(new HSSFRichTextString(staff.getStaffName()));
}
response.getOutputStream();
// 新規ファイルの輸出流、輸入流
File file = new File(path);
// 指定パースがない場合 生成パス
if (!file.exists()) {
file.mkdirs();
}
FileOutputStream fos = null;
try {
// 生成するファイルパス
fos = new FileOutputStream(outputPath + "/" + fileName + ".xls");
hb.write(fos);
// 指定パースに新excelファイルを生成
fos.flush();
} catch (IOException ie) {
ie.printStackTrace();
System.out.println("the IOException error,1081 lines in the system");
} finally {
if (fos != null) {
// ファイルの輸出流を閉める
fos.close();
fos = null;
}
// 以前生成した lzh圧縮ファイルを削除
// deleteFile(outputPath, "lzh", dateString);
// lzh圧縮ファイル生成
// getZipFile(outputPath, fileName + ".xls", outputPath, fileName+ ".lzh");
// 生成した excelファイルを削除
// deleteFile(outputPath, "xls", dateString);
}
// lzh圧縮ファイル名
/*
* fileName = fileName+".lzh"; // lzh圧縮ファイルパス String filepath = outputPath; // response設定とダウンロード保存のファイル名
* response.reset();
*/
// Excelファイル名
fileName = fileName + ".xls";
StringBuffer sb = new StringBuffer();
sb.append("attachment; filename=\"");
sb.append(new String(fileName.getBytes("SJIS"), "UTF-8"));
sb.append("\"");
response.reset();
response.setContentType("text/html;charset=UTF-8");
response.setContentType("application/x-msdownload");
response.setHeader("Content-Disposition", sb.toString());
// ファイルの輸出流、輸入流
OutputStream output = null;
FileInputStream fis = null;
try {
File f = new File(outputPath + File.separator + fileName);
// ファイルの輸出流
output = response.getOutputStream();
// ファイルの輸入流
fis = new FileInputStream(f);
byte[] b = new byte[(int) f.length()];
// 画面で表示する
int i = 0;
while ((i = fis.read(b)) > 0) {
output.write(b, 0, i);
}
output.flush();
} catch (Exception e) {
e.printStackTrace();
System.out.println("the Exception error,1132 lines in the system");
} finally {
if (fis != null) {
// ファイルの輸入流を閉める
fis.close();
fis = null;
}
if (output != null) {
// ファイルの輸出流を閉める
output.close();
output = null;
}
}
...全文
相关推荐
C# 创建Excel 加Excel下拉框列,并且给下拉框动态赋值
用C#创建Excel并且给Excel添加下拉框列,并可以动态给Excel的下拉框动态赋值,总结了一个星期,才做出来的,开始对Excel不懂,所以比较慢,应该很有用处的,大家可以看看,多多支持
321套Excel可视化图表、Excel模板(在Excel里面实现数据可视化),史上最全Excel可视化图表,模板
321套Excel可视化图表、Excel模板(在Excel里面实现数据可视化),史上最全Excel可视化图表,模板
java实现自定义excel模板导出excel并可保存客户端和在线打开
java生成自定义模板的excel,可以实现任何复杂格式的excel,简单易用,可以保存客户端并可在线打开,使用了jxl技术,不需要任何插件,jar包都有可以直接运行
用EXCEL批量更改照片的名字
用EXCEL批量更改照片的名字,用EXCEL批量更改照片的名字。
EXCEL实现套用模板批量打印行信息
EXCEL实现套用模板批量打印行信息。数据源表是标准的格式表,另外建立模板,通过宏实现EXCEL套用模板批量打印行信息。


