如果通过单击按扭生成文件?
我想在网页上单击按扭,就会把刚才从数据库查询到的数据导入到excel里面去,请问这怎么实现?
[解决办法]
看看下面这段程序:
public static HSSFWorkbook highlightExcel_view(Vector tmpVector, String excel_flag) throws Exception {
String empno= " ";
String user_id= " ";
String full_name= " ";
String app_id= " ";
String excel_subject = " ";
HSSFWorkbook wb = new HSSFWorkbook();
if( "terminate ".equals(excel_flag))
excel_subject = "Terminate User List ";
HSSFSheet sheet1 = wb.createSheet(excel_subject);
HSSFRow row = null;
HSSFCell cell = null;
HSSFCellStyle cellBorderBoldStyle= wb.createCellStyle();
HSSFCellStyle cellBoldStyle= wb.createCellStyle();
HSSFCellStyle cellBorderStyle= wb.createCellStyle();
HSSFCellStyle cellStyle= wb.createCellStyle();
HSSFFont boldFont = wb.createFont();
HSSFFont font = wb.createFont();
boldFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
cellBoldStyle.setFont(boldFont);
cellBorderStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
cellBorderStyle.setBottomBorderColor(HSSFColor.BLACK.index);
cellBorderStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
cellBorderStyle.setLeftBorderColor(HSSFColor.BLACK.index);
cellBorderStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
cellBorderStyle.setRightBorderColor(HSSFColor.BLACK.index);
cellBorderStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
cellBorderStyle.setTopBorderColor(HSSFColor.BLACK.index);
// start writing on sheet 1 (transfer in )
// row 0
row = sheet1.createRow((short)0);
if( "terminate ".equals(excel_flag)){
cell = FieldData.createStringCell(row, 0, "Terminate User Account List ", cellBoldStyle);
// row1
row = sheet1.createRow((short)1);
cell = FieldData.createStringCell(row, 0, "Emp NO. ", cellBoldStyle);
cell = FieldData.createStringCell(row, 1, "Full Name ", cellBoldStyle);
cell = FieldData.createStringCell(row, 2, "Terminate Date ", cellBoldStyle);
cell = FieldData.createStringCell(row, 3, "User Id ", cellBoldStyle);
cell = FieldData.createStringCell(row, 4, "Appcation ", cellBoldStyle);
}
sheet1.addMergedRegion(new Region(0,(short)0, 0,(short)0));
for(int j=0;j <tmpVector.size();j++){
row = sheet1.createRow((short)(j+2));
for(int k=0; k < ((Vector)tmpVector.get(j)).size()-3; k++)
cell = FieldData.createStringCell(row, k,((Vector)tmpVector.get(j)).get(k).toString(), cellBorderStyle);
sheet1.addMergedRegion(new Region(0,(short)0, 0,(short)2));
}
return wb;
}
[解决办法]
这个你得找有第三方jar包
基本上都有例子的
比较简单
"利用JAVA操作EXCEL文件(JAVA EXCEL API) "
http://www.88doc.com/88doc/software/java/2/2_1168879968090.html
[解决办法]
写个ActiveX控件,调用其方法,把文件生成在IE的零食目录下面,生成完后打开它
------解决方案--------------------
我不明白,你既然要去后台DB中查数据,那又为什么非要在客户端生成excel档呢?
ExcelApp = new ActiveXObject( "Excel.Application ");
ExcelApp.DisplayAlerts = false;
ExcelWorkbooks = ExcelApp.Workbooks;
ExcelWorkbooks.open( "....:\\tmp.xls ");
ExcelWorkbooks( "tmp.xls ").Activate;
ExcelApp.Sheets(1).Name = "tttt ";
ActiveSheet = ExcelWorkbooks( "tmp.xls ").Sheets(1);
ActiveSheet.Name = "sheet name ";
alert(ExcelApp.Sheets(1).Cells(1, 1).Value , 0 , "cell value ");
[解决办法]
关注
[解决办法]
关注
[解决办法]
http://dev.csdn.net/article/75/75272.shtm
需要引入jxl.jar包
[解决办法]
没那么麻烦的,告诉你个很简单的方法,你做一个和你这个页一样的页,在最上面引用的那里加入下面这段话,看效果吧,你会满意的
<% response.setContentType( "application/vnd.ms-excel;charset=GBK "); %>