我的问题也没有人回答,我也想哭:(我是用apache的poi操作excel的,具体操作word我没有用过,不知道。顺便问下我的问题:问个关于apache的poi操作excel的问题,谢谢 大家好,问个问题。
用apache的poi操作excel的时候想给一个字段添加超链接怎么做呢?应为字段太多
了,所以手工添加很浪费时间,有没有办法解决谢谢!
用apache的poi操作excel的时候想给一个字段添加超链接怎么做呢?应为字段太多
了,所以手工添加很浪费时间,有没有办法解决谢谢!
<script language=vbscript>
function CopyMeWord()
dim app
set app = createobject ("Word.Application")
app.Visible = true
set x = app.documents.add()
parent.moonpiazza.document.execCommand ("selectall")
parent.moonpiazza.document.execCommand ("copy")
parent.moonpiazza.document.execCommand ("unselect")
app.ActiveDocument.PageSetup.Orientation = wdOrientLandscape
app.Selection.Paste
app.Application.Visible = True
end function function CopyMeExcel()
dim objExcelApp
set objExcelApp = createobject ("Excel.Application")
parent.moonpiazza.document.execCommand ("selectall")
parent.moonpiazza.document.execCommand ("copy")
parent.moonpiazza.document.execCommand ("unselect")
Set objExcelBook = objExcelApp.workbooks.add '鏂板妾旀鏂规硶
Set objExcelSheets = objExcelBook.Worksheets
Set objExcelSheet = objExcelBook.Sheets(1)
objExcelSheet.Activate
objExcelSheet.Paste
objExcelApp.Visible = true
objExcelApp.Application.Visible = True
end function
</script>
String filepath :应用服务器的路径
String[] para :参数
ResultSet rs:结果集 public void toExcel(ResultSet rs, String filepath, String[] para, String ExcelId, String login) { try { //获取系统日期做为制日期
Calendar date = java.util.Calendar.getInstance();
String reData = "";
String year = String.valueOf(date.get(Calendar.YEAR));
String m1 = String.valueOf(date.get(Calendar.MONTH));
String d = String.valueOf(date.get(Calendar.DATE)); int month = Integer.parseInt(m1) + 1;
if (month < 10) {
m1 = "0" + String.valueOf(month);
}
int da = Integer.parseInt(d);
if (da < 10) {
d = "0" + String.valueOf(da);
} reData = year + "-" + m1 + "-" + d;
//获取日期结束 // 创建新的Excel 工作簿
HSSFWorkbook workbook = new HSSFWorkbook();
// 在Excel工作簿中建一工作表,其名为缺省值
HSSFSheet sheet = workbook.createSheet();
//设置Excel的显示格式 //设置行头
String[] str = new String[8];
str[0] = "制表日期";//"制表日期";
str[1] = reData;//当前日期
str[2] = "";
str[3] = "";
str[4] = "";
str[5] = "";
str[6] = "";
str[7] = "";
String[] str1 = new String[8]; str1[0] = "查询时间";//"保险产品";
str1[1] = para[1];
str1[2] = "";
str1[3] = "";
str1[4] = "";
str1[5] = "";
str1[6] = "制表用户";
str1[7] = login; //设置行头
String[] str2 = new String[8];
str2[0] = "保险产品";
str2[1] = "航班号";
str2[2] = "工作号";
str2[3] = "保费";
str2[4] = "保额";
str2[5] = "旅客姓名";
str2[6] = "证件号";
str2[7] = "销售日期";
//设置行头
String[] str4 = new String[8];
str4[0] = "";
str4[1] = "";
str4[2] = "";
str4[3] = "历史";
if (ExcelId.equals("DayReportToExcel")) {
str4[3] = "当日";
}
str4[4] = "报表";
str4[5] = "";
str4[6] = "";
str4[7] = "";
HSSFRow row;
HSSFCell cell;
HSSFCellStyle style;
HSSFFont hf; for (int i = 0; i < 4; i++) {
//在索引0的位置创建行(最顶端的行)
row = sheet.createRow((short) i);
for (int j = 0, a = 0; j < 8; a++, j++) { //在索引0的位置创建单元格(左上端)(相当于列数)
cell = row.createCell((short) j);
//定义单元格为字符串类型
cell.setCellType(HSSFCell.CELL_TYPE_STRING); //定义样式
style = workbook.createCellStyle();
//创建工作本的字体
hf = workbook.createFont();
hf.setFontName("楷体_GB2312");
style.setFont(hf);
//设置列的属性
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellStyle(style); //在所创建的单元格填入值
if (i == 0) {
cell.setCellValue(str4[a]);
}
if (i == 1) {
cell.setCellValue(str[a]);
}
if (i == 2) {
cell.setCellValue(str1[a]);
}
if (i == 3) {
cell.setCellValue(str2[a]);
}
}
} int n = 4, m = 0, s = 0;
// 获取结果集的行数
while (rs.next()) {
row = sheet.createRow((short) n++); //从第5行开始 cell = row.createCell((short) m++); //从第4列开始
//定义单元格为字符串类型
cell.setCellType(HSSFCell.CELL_TYPE_STRING); //填加保险产品
cell.setCellValue(rs.getString("TYPE"));
//填加航班号
cell = row.createCell((short) m++); //从第5列开始
cell.setCellValue(rs.getString("FLIGHT_No"));
//填加工作号
cell = row.createCell((short) m++); //从第6列开始
cell.setCellValue(rs.getString("SALES"));
//填加保费 TYPE, FLIGHT_No, SALES, INSURED_AMOUNT, PREMIUM, Tel,
// DateTOday
cell = row.createCell((short) m++); //从第7列开始
String StrTemp = rs.getString("PREMIUM");
cell.setCellValue(StrTemp);
//填加保额
cell = row.createCell((short) m++); //从第8列开始
//定义样式
style = workbook.createCellStyle();
//创建工作本的字体
hf = workbook.createFont();
hf.setFontName("楷体_GB2312");
style.setFont(hf);
//设置列的属性
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellStyle(style); cell.setCellValue(rs.getString("INSURED_AMOUNT"));
//填加旅客姓名
cell = row.createCell((short) m++); //从第9列开始
//定义样式
style = workbook.createCellStyle();
//创建工作本的字体
hf = workbook.createFont();
hf.setFontName("楷体_GB2312");
style.setFont(hf);
//设置列的属性
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellStyle(style);
cell.setCellValue(rs.getString("NAME_OF_THE_INSURED"));
//增加旅客证件号
cell = row.createCell((short) m++); //从第9列开始
cell.setCellValue(rs.getString("ID_CARD_No"));
//填加销售日期
cell = row.createCell((short) m++); //从第10列开始
cell.setCellValue(rs.getString("DateTOday")); if (m >= 7) {
m = 0;
} }
// 新建一输出文件流
FileOutputStream fOut = new FileOutputStream(filepath);
// 把相应的Excel 工作簿存盘
workbook.write(fOut); fOut.flush();
// 操作结束,关闭文件
fOut.close(); } catch (Exception e) {
System.out.println("已运行 xlCreate() :错误信息 " + e);
throw new RuntimeException(e.getMessage());
}
}
关于这个有问题可以帮你一下.