[利用java怎么实现生成报表Excel文件]JAVA POI 组件 //创建HSSFWorkbook对象 HSSFWorkbook wb = new HSSFWorkbook(); //创建HSSFSheet对象 HSSFSheet sheet = wb.createSheet("sheet0"); //创建HSSFRow对象 HSSFRow...+阅读
1
2
3
4
5
6
7
8
importjava.io.File;
publicclassTest {
publicstaticvoidmain(String[] args) throwsException {
2113File f = newFile("d:/1.xls");
f.createNewFile();
}
}
好吧,之前没看到“用poi”这句话。现在下面的是用poi的:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
importjava.io.FileOutputStream;
importjava.io.IOException;
importorg.apache.poi.hssf.usermodel.HSSFWorkbook;
publicclassTest {
publicstaticvoidmain(String[] args) {
try{
HSSFWorkbook workbook = newHSSFWorkbook();
FileOutputStream fileOut = newFileOutputStream("D:/2.xls");
workbook.write(fileOut);
fileOut.close();
} catch(IOException e) {
e.printStackTrace();
}
}
}
java如何生成excel具体的
poi或jxl都行
你从网上下载个jxl.jar的jar包
简单说一下jxl导出excel过程
//先创建一个excel文件
String excelPath = "D:\\系统用户.xls";
File excelFile = new File(excelPath);
if (!excelFile.exists()) {
excelFile.createNewFile();
}
WritableWorkbook book = Workbook.createWorkbook(excelFile);
WritableSheet ws = book.createSheet("用户信息", 0); //新建一个sheet
---------------
//往表中添加内容
ws.addCell(WritableCell )
------------
//将数据写入所建的excel
book.write();
book.close();
java怎样输出excel文件
//java生成简单的Excel文件
package beans.excel;
import java.io.IOException;
import java.io.OutputStream;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
public class SimpleExcelWrite {
public void createExcel(OutputStream os) throws WriteException,IOException{
//创建工作薄
WritableWorkbook workbook = Workbook.createWorkbook(os);
//创建新的一页
WritableSheet sheet = workbook.createSheet("First Sheet",0);
//创建要显示的内容,创建一个单元格,第一个参数为列坐标,第二个参数为行坐标,第三个参数为内容
Label xuexiao = new Label(0,0,"学校");
sheet.addCell(xuexiao);
Label zhuanye = new Label(1,0,"专业");
sheet.addCell(zhuanye);
Label jingzhengli = new Label(2,0,"专业竞争力");
sheet.addCell(jingzhengli);
Label qinghua = new Label(0,1,"清华大学");
sheet.addCell(qinghua);
Label jisuanji = new Label(1,1,"计算机专业");
sheet.addCell(jisuanji);
Label gao = new Label(2,1,"高");
sheet.addCell(gao);
Label beida = new Label(0,2,"北京大学");
sheet.addCell(beida);
Label falv = new Label(1,2,"法律专业");
sheet.addCell(falv);
Label zhong = new Label(2,2,"中");
sheet.addCell(zhong);
Label ligong = new Label(0,3,"北京理工大学");
sheet.addCell(ligong);
Label hangkong = new Label(1,3,"航空专业");
sheet.addCell(hangkong);
Label di = new Label(2,3,"低");
sheet.addCell(di);
//把创建的内容写入到输出流中,并关闭输出流
workbook.write();
workbook.close();
os.close();
}
}
java代码怎么导出excel文件
excel工具类 package com.ohd.ie.product.action; import java.awt.image.BufferedImage; import java.io.*; import javax.imageio.ImageIO; import org.apache.commons.io.output.ByteArrayOutputStream; import jxl.Workbook; import jxl.format.Alignment; import jxl.format.VerticalAlignment; import jxl.write.*; import jxl.write.Number; import jxl.write.biff.RowsExceededException; public class Excel { private OutputStream os; private WritableWorkbook wwb = null; private WritableSheet ws = null; private WritableCellFormat titleCellFormat = null; private WritableCellFormat noBorderCellFormat = null; private WritableCellFormat hasBorderCellFormat = null; private WritableCellFormat hasBorderCellNumberFormat = null; private WritableCellFormat hasBorderCellNumberFormat2 = null; private WritableImage writableImage=null; private int r; public Excel(OutputStream os){ this.os = os; r = -1; try { wwb = Workbook.createWorkbook(os);//创建工作表 ws = wwb.createSheet("sheet1",0);//设置表头字体,大小,加粗 titleCellFormat = new WritableCellFormat(); titleCellFormat.setAlignment(Alignment.CENTRE); titleCellFormat.setVerticalAlignment(VerticalAlignment.CENTRE);//自动换行 titleCellFormat.setWrap(true); titleCellFormat.setFont(new WritableFont(WritableFont.createFont("宋体"),12,WritableFont.BOLD)); titleCellFormat.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN);//设置表格字体,大小----无边框 noBorderCellFormat = new WritableCellFormat(); noBorderCellFormat.setAlignment(Alignment.CENTRE); noBorderCellFormat.setVerticalAlignment(VerticalAlignment.CENTRE); noBorderCellFormat.setFont(new WritableFont(WritableFont.createFont("宋体"),12));//设置表格字体,大小----有边框 hasBorderCellFormat = new WritableCellFormat(); hasBorderCellFormat.setAlignment(Alignment.CENTRE); hasBorderCellFormat.setVerticalAlignment(VerticalAlignment.CENTRE); hasBorderCellFormat.setFont(new WritableFont(WritableFont.createFont("宋体"),12)); hasBorderCellFormat.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN);//设置表格字体,大小----有边框(小数) NumberFormat nf = new NumberFormat("#0.00"); hasBorderCellNumberFormat = new WritableCellFormat(nf); hasBorderCellNumberFormat.setAlignment(Alignment.CENTRE); hasBorderCellNumberFormat.setVerticalAlignment(VerticalAlignment.CENTRE); hasBorderCellNumberFormat.setFont(new WritableFont(WritableFont.createFont("宋体"),12)); hasBorderCellNumberFormat.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN);//设置表格字体,大小----有边框(整数) NumberFormat nf2 = new NumberFormat("#0"); hasBorderCellNumberFormat2 = new WritableCellFormat(nf2); hasBorderCellNumberFormat2.setAlignment(Alignment.CENTRE); hasBorderCellNumberFormat2.setVerticalAlignment(VerticalAlignment.CENTRE); hasBorderCellNumberFormat2.setFont(new WritableFont(WritableFont.createFont("宋体"),12)); hasBorderCellNumberFormat2.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN); } catch (Exception e) {// TODO Auto-generated catch block e.printStackTrace(); } }/**** param content 内容* param c 列* param style 样式* param isNewLine 是否换行* param mergeType 合并类型* param mergeCount 合并个数* param width 单元格宽*/ public void setExcelCell(String content,int c,int style,boolean isNewLine,int mergeType,int mergeCount,int width){ try {////////////////////////////////////////////////////////////////////////////////////////////////////////////////////报表内容//////////////////////////////////////////////////////////////////////////////////////////////////////////////////// if(isNewLine){ r++; } WritableCell l = null; if(style == 1){ l = new Label(c,r,content,titleCellFormat); } else if(style == 2){ l = new Label(c,r,content,noBorderCellFormat); } else if(style == 3){ l = new Label(c,r,content,hasBorderCellFormat); } else if(style == 4){ l = new Number(c,r,Double.parseDouble(content),hasBorderCellNumberFormat); } else if(style == 5){ l = new Number(c,r,Integer.parseInt(content),hasBorderCellNumberFormat2); } ws.addCell(l); if(width != 0){ ws.setColumnView(c,width); }//veryhuo,com if(mergeType == 1){//x 轴方向 ws.mergeCells(c, r, c+mergeCount-1 , r); } else if(mergeType == 2){//y 轴方向 ws.mergeCells(c, r, c, r+mergeCount-1); } if(isNewLine){ ws.setRowView(r, 350); if(style == 1 & r != 0){ ws.setRowView(r, 900); } else{ ws.setRowView(r, 350); } }////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// } catch (Exception e) { System.out.println(e.toString()); } } public void ...
以下为关联文档:
java代码生成word文件没定格式的话可以再jsp页面添加这段: <% response.reset(); response.setContentType("application/vnd.ms-excel;charset=UTF-8"); java.util.Date date = new Date(); DateFo...
在Excel里如何实现自动生成备份文件到另一个文件夹可以用宏来实现写在工作表事件下,但你要事先在宏里写好路径。 Private Sub Workbook_BeforeClose(Cancel As Boolean) a = ActiveWorkbook.Name ActiveWorkbook.SaveAs Filen...
请问如何用java创建两个stack一个是数字一个是符号public void push(Object obj){ if(obj.getClass().getType().getName().equals("int")) { stack1.push(obj); }else if(a[i].getType().getName().equals("class java.lang.In...
您好请问运行多个excel文件合并成一个文件宏命令其中一条代码1、把两个excel表格放在同一个文件夹内。 2、用microsoft excel打开新建的excel表,并右键单击sheet1,找到“查看代码”,单击进去。进去之后就看到了宏计算界面。如图所示。 3、...
如何用java代码生成一个大数据的excel文件POI包解析 或者 只是xls的话 用 jxl 也行 poi 全支持 xls 和xlsx 然后写入 保存 ok HSSFSheet sheet= null; for(int sherrt= 0; sherrt sheet = wr.getSheetAt(sherrt); //...
如何用VB代码创建一个ACCESS的MDB文件Dim MyDB As Database, MyWS As WorkspaceDim AuTd As TableDef, TitTd As TableDef, PubTd As TableDefDim AuFids (2) As Field, TitFids (5) As Field, PubFids (10) As...
vb用代码创建mdb文件以及对表的操作使用Create方法 ===================== DBName = "c:\myAccessDB.mdb" Set myCat = CreateObject("ADOX.Catalog") myCat.Create "Provider=Microsoft.Jet.OLEDB.4.0;Data Source...
急!如何用VB代码创建一个名为用代码创建数据库,表,字段Option ExplicitPrivate db As DatabasePrivate td As TableDefPrivate f As FieldPrivate Sub Command1_Click()Set db = DBEngine.CreateDatabase(...
如何使用Java POI生成Excel表文件private static void WriteExcel2010() throws IOException { String path="C:\\poi2.xlsx"; XSSFWorkbook workbook=new XSSFWorkbook(); XSSFSheet sheet=workbook.createSh...