「JAVA怎么进行报表导出」java实现导出excel报表

博主:adminadmin 2022-11-22 23:29:08 83

今天给各位分享JAVA怎么进行报表导出的知识,其中也会对java实现导出excel报表进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

java导出excel

java导出Excel

java 代码 /* * Generated by MyEclipse Struts * Template path: templates/java/JavaClass.vtl */ package com.axon.fable.sams.view.action; import java.io.IOException; import java.io.OutputStream; import java.util.List; import javax.serv ...

java导出Excel例举方式

方法一:导出Excel数据的插件jexcelapi

程序实例如下:

public void exportClassroom(OutputStream os) throws PaikeException {

try {

WritableWorkbook wbook = Workbook.createWorkbook(os); //建立excel文件

WritableSheet wsheet = wbook.createSheet("教室信息表", 0); //工作表名称

//设置Excel字体

WritableFont wfont = new WritableFont(WritableFont.ARIAL, 16,

WritableFont.BOLD, false,

jxl.format.UnderlineStyle.NO_UNDERLINE,

jxl.format.Colour.BLACK);

WritableCellFormat titleFormat = new WritableCellFormat(wfont);

String[] title = { "教室名", "容 量", "类 型", "其他说明" };

//设置Excel表头

for (int i = 0; i title.length; i++) {

Label excelTitle = new Label(i, 0, title[i], titleFormat);

wsheet.addCell(excelTitle);

}

int c = 1; //用于循环时Excel的行号

ClassroomService cs = new ClassroomService();

List list = cs.findAllClassroom(); //这个是从数据库中取得要导出的数据

Iterator it = list.iterator();

while (it.hasNext()) {

ClassroomDTO crdto = (ClassroomDTO) it.next();

Label content1 = new Label(0, c, crdto.getRoomname());

Label content2 = new Label(1, c, crdto.getCapicity().toString());

Label content3 = new Label(2, c, crdto.getRoomTypeId()

.toString());

Label content4 = new Label(3, c, crdto.getRemark());

wsheet.addCell(content1);

wsheet.addCell(content2);

wsheet.addCell(content3);

wsheet.addCell(content4);

c++;

}

wbook.write(); //写入文件

wbook.close();

os.close();

} catch (Exception e) {

throw new PaikeException("导出文件出错");

}

}

方法二:直接用Java代码实现导出Excel报表

/*

* Generated by MyEclipse Struts

* Template path: templates/java/JavaClass.vtl

*/

package com.axon.fable.sams.view.action;

import java.io.IOException;

import java.io.OutputStream;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import jxl.Workbook;

import jxl.write.WriteException;

import jxl.write.biff.RowsExceededException;

import org.apache.struts.action.ActionForm;

import org.apache.struts.action.ActionForward;

import org.apache.struts.action.ActionMapping;

import org.hibernate.HibernateException;

import org.hibernate.Query;

import org.hibernate.Session;

import org.hibernate.Transaction;

import com.axon.fable.empolderpackage.out.OutJavaScript;

import com.axon.fable.empolderpackage.page.Pager;

import com.axon.fable.empolderpackage.string.MyPublic;

import com.axon.fable.sams.common.BaseAction;

import com.axon.fable.sams.exception.AppBusinessException;

import com.axon.fable.sams.exception.AppSystemException;

/**

* MyEclipse Struts

* Creation date: 06-28-2007

*

* XDoclet definition:

* @struts.action path="/axon" name="axonForm" input="/samspage/zm/axon.jsp" parameter="method" scope="request" validate="true"

* @struts.action-forward name="success" path="/samspage/zm/content.jsp"

*/

public class StshipoperationAction extends BaseAction {

/*

* Generated Methods

*/

private static Session session=null;

private static Transaction ts=null;

private static Query queryC=null;

private static Query queryR=null;

private static Query query=null;

private static List list=null;

private static Integer startRow;

private static Integer ncurrentPage;

private static Integer cell;

private static String property;

private static String sql;

private static String type;

private static String condition ;//是否导出当前页

private static String currentPage;

private static String from ;

private static String pactdata;

private static String voyagename;

private static String voyageno;

private static String dwt ;

private static String hirefrom ;

private static String deliveryposion ;

private static String redeliveryposion ;

private static String sheepowner ;

private static String addr;

private static String addcomm;

private static String rent;

private static String fileName ;

private static OutputStream os;

@Override

public ActionForward findAll(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {

// TODO Auto-generated method stub

return null;

}

@Override

public ActionForward findById(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {

// TODO Auto-generated method stub

return null;

}

@Override

public ActionForward save(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {

// TODO Auto-generated method stub

return null;

}

public static String strNull(Object nullStr,String newStr,Integer cell){

if(nullStr==null||nullStr.equals("")){return newStr;}else{cell+=1;return nullStr+"";}

}

public static String getStr(String str,Integer cell){

if(str==null||str.trim().equals("")){return "";}else{cell+=1;return ","+str;}

}

public static String getExcelTile(String title){

if(title==null)

return "";

if(title.equals("modela.stsid"))

return "编号";

if(title.equals("modelc.pactdata"))

return "合同日期";

if(title.equals("modela.voyagename"))

return "航名";

if(title.equals("modela.voyageno"))

return "航次";

if(title.equals("modelc.dwt"))

return "DWT";

if(title.equals("modelc.hirefrom"))

return "受载期";

if(title.equals("modela.deliveryposion"))

return "交船地点";

if(title.equals("modela.redeliveryposion"))

return "还船地点";

if(title.equals("modelc.sheepowner"))

return "联系人";

if(title.equals("modelc.addr"))

return "经纪人拥金";

if(title.equals("modelc.addcomm"))

return "ADD COMM";

if(title.equals("modelc.rent"))

return "租金";

return "";

}

public ActionForward exporVoyagesInfoToExcel(ActionMapping mapping, ActionForm form,

HttpServletRequest request, HttpServletResponse response) {

list=null;

startRow=0;

ncurrentPage=1;

cell=0;

type =request.getParameter("type");

condition =request.getParameter("condition");//是否导出当前页

currentPage =request.getParameter("currentPage");

from =request.getParameter("from");

pactdata = request.getParameter("modelc.pactdata");

voyagename = request.getParameter("modela.voyagename");

voyageno = request.getParameter("modela.voyageno");

dwt = request.getParameter("modelc.dwt");

hirefrom = request.getParameter("modelc.hirefrom");

deliveryposion = request.getParameter("modela.deliveryposion");

redeliveryposion = request.getParameter("modela.redeliveryposion");

sheepowner = request.getParameter("modelc.sheepowner");

addr = request.getParameter("modelc.addr");

addcomm = request.getParameter("modelc.addcomm");

rent = request.getParameter("modelc.rent");

if(type!=nulltype.trim().equals("1")){

type ="已还船舶--费用未结清";

}else{

type ="已还船舶--费用已结清";

}

property =getStr(pactdata,cell)+getStr(voyagename,cell)+getStr(voyageno,cell)+getStr(dwt,cell)+getStr(hirefrom,cell)

+getStr(deliveryposion,cell)+getStr(redeliveryposion,cell)+getStr(sheepowner,cell)+getStr(addr,cell)+getStr(addcomm,cell)

+getStr(rent,cell);

property = property.substring(1);

String split[] = property.split(",");

// System.out.println("-----------------------------property:"+property);

if(currentPage!=null!currentPage.trim().equals("")){

ncurrentPage =Integer.parseInt(currentPage);

}else{

OutJavaScript.outString(response, "Sorry! Failed to get information of pager.");

return null;

}

try {

session =getServiceLocator().getBaseHibernateDAO().getSession();

sql ="select count(*) "+from;

query =session.createQuery(sql);

list = query.list();

for (int i = 0; i list.size(); i++) {

totalSize =(Integer)list.get(i);

if(totalSize!=0){

pager =new Pager(ncurrentPage,totalSize);

}

}

query =getServiceLocator().getBaseHibernateDAO().getSession().createQuery("select " +property+from);

if(condition!=nullcondition.trim().equals("1")){//分页数据

startRow = (ncurrentPage - 1)*pager.getPageSize();

query.setFirstResult(startRow);

query.setMaxResults(pager.getPageSize());

// System.out.println("---------------------------------------------------query:"+query);

}

list = query.list();

fileName = "shipInfo";

os = response.getOutputStream();

response.reset();

response.setHeader("Content-disposition",

"attachment; filename=" +fileName + ".xls");

response.setContentType("application/msexcel");

jxl.write.WritableWorkbook wbook = Workbook.createWorkbook(os);

jxl.write.WritableSheet wsheet = wbook.createSheet("the first sheet", 0);

for (int i = 0; i split.length; i++) {

jxl.write.Label wlabel0;

wlabel0 = new jxl.write.Label(i, 0, getExcelTile(split[i]));

wsheet.addCell(wlabel0);

}

jxl.write.Label wlabel1;

for(int i=0;ilist.size();i++) {

if(split.length==1){

Object strval = (Object) list.get(i);

String javaScript=""+MyPublic.toHtmlStr(strval==null?"":strval.toString().trim())+"";

wlabel1 = new jxl.write.Label(0, i+1,strval==null?"":strval.toString().trim() );

wsheet.addCell(wlabel1);

}else{

Object[] strval = (Object[]) list.get(i);

for(int j=0;jstrval.length;j++) {

String javaScript=""+MyPublic.toHtmlStr(strval[j]==null?"":strval[j].toString().trim())+"";

//System.out.println("===================script:"+javaScript);

wlabel1 = new jxl.write.Label(j, i+1,strval[j]==null?"":strval[j].toString().trim() );

wsheet.addCell(wlabel1);

}

}

}

wbook.write();

response.flushBuffer();

wbook.close();

os.close();

} catch (IOException e) {

// TODO Auto-generated catch block

OutJavaScript.outString(response, "Sorry! Export Excel exception.");

e.printStackTrace();

} catch (HibernateException e1) {

// TODO Auto-generated catch block

OutJavaScript.outString(response, "Sorry! Database exception.");

e1.printStackTrace();

} catch (AppSystemException e1) {

// TODO Auto-generated catch block

OutJavaScript.outString(response, "Sorry! System exception.");

e1.printStackTrace();

} catch (AppBusinessException e1) {

// TODO Auto-generated catch block

OutJavaScript.outString(response, "Sorry! Database exception.");

e1.printStackTrace();

} catch (RowsExceededException e) {

// TODO Auto-generated catch block

OutJavaScript.outString(response, "Sorry! Export Excel exception.");

e.printStackTrace();

} catch (WriteException e) {

// TODO Auto-generated catch block

OutJavaScript.outString(response, "Sorry! Export Excel exception.");

e.printStackTrace();

}

return null;

}

@Override

public ActionForward update(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {

// TODO Auto-generated method stub

return null;

}

}

还有其他很多种 字数限制 无法一一举例方式

java中怎么把报表导出到excel

导入数据库

@RequestMapping("/uploadOrderFile")

@ResponseBody

public Object uploadOrderFile(HttpServletRequest request, HttpServletResponse response,@RequestParam(value = "file") MultipartFile[] files) throws ServletException, IOException, ParseException{

Workbook rwb=null;

if(files!=null  files.length0){

       try {

     // String filePath = request.getSession().getServletContext().getRealPath("/") + "\\uploadOrderFile\\" +  files.getOriginalFilename();

     // System.out.println("----------"+filePath);

     rwb = Workbook.getWorkbook(files[0].getInputStream());

     Sheet rs=rwb.getSheet(0);//默认0是第一张表,或者rwb.getSheet(Sheet1)Excel要导入的表名

     int clos=rs.getColumns();//得到所有的列

     int rows=rs.getRows();//得到所有的行

        //存放Excel表抬头名称以及对应的列

        MapInteger,Object map=new HashMapInteger, Object();

        //实体类集合存放每次循环获得的值

        ListMedicine medicineList=new ArrayListMedicine();  

        for (int i = 0; i  rows; i++) {

          //创建实体类

        Medicine medicine=new Medicine();

         if(i==0){//遍历第一行获取抬头跟对应的列

          for (int j = 0; j clos; j++) {//取得每个抬头名称对应的列           

          if(rs.getCell(j, i).getContents().equals("品名")){

          map.put(j,"品名");

          }else if(rs.getCell(j, i).getContents().equals("商品编号")){

          map.put(j,"商品编号");

          }else if(rs.getCell(j, i).getContents().equals("生产日期")){

          map.put(j,"生产日期");

          }else if(rs.getCell(j, i).getContents().equals("产地")){

          map.put(j,"产地");  

          }else if(rs.getCell(j, i).getContents().equals("生产厂家")){

          map.put(j,"生产厂家");

          }else if(rs.getCell(j, i).getContents().equals("批号")){

          map.put(j,"批号");

          }

          }

         }else{         

          //循环遍历map 》》》存的Excel表的抬头名称以及对应的列

          for (int j = 0; j  clos; j++) {

          if(map.get(j)==null){//如果=null 进入下一个循环

          continue;

          }

          if(map.get(j).equals("品名")){

          //如果为空结束当前循环,进入下一个循环

         if(rs.getCell(j, i).getContents()==null||rs.getCell(j, i).getContents().equals("")){

         continue;

         }           

          medicine.setMedicineName(rs.getCell(j, i).getContents());

          }else if(map.get(j).equals("商品编号")map.get(j)!=null){

          //如果为空结束当前循环,进入下一个循环

         if(rs.getCell(j, i).getContents()==null||rs.getCell(j, i).getContents().equals("")){

         continue;

         }  

          medicine.setMedicineCode(rs.getCell(j, i).getContents());           

          }else if(map.get(j).equals("生产日期")map.get(j)!=null){

          medicine.setCreateTime(rs.getCell(j, i).getContents());

          if(rs.getCell(j, i).getContents()!=null  !rs.getCell(j, i).getContents().equals("")){

          //如果生产日期存在 则+三年给到期日期赋值

          //CommonUtil.getMedicineEffectiveTime为封装好的类

          medicine.setEffectTime(CommonUtil.getMedicineEffectiveTime(rs.getCell(j, i).getContents(),3));

          }

          }else if(map.get(j).equals("产地")map.get(j)!=null){

          medicine.setAddress(rs.getCell(j, i).getContents());

          

          }else if(map.get(j).equals("生产厂家")map.get(j)!=null){

          medicine.setProducingArea(rs.getCell(j, i).getContents());

        

          }else if(map.get(j).equals("批号")map.get(j)!=null){

          medicine.setBatchNumber(rs.getCell(j, i).getContents());

          }         

          }

          medicineList.add(medicine);//获得的值放入集合中                    

         }         

        }

        //新增用到的list

        ListMedicine addList=new ArrayListMedicine(); 

        //修改用到的list

        ListMedicine updateList=new ArrayListMedicine(); 

        //导入数据

        for(int i=0;imedicineList.size();i++){      

         //判断商品编号是否存在

         if(medicineService.selectMedicineCode(medicineList.get(i).getMedicineCode()).size()0){

         //如果存在则修改         

         updateList.add(medicineList.get(i));        

         }else{         

         addList.add(medicineList.get(i));        

         }

      }

        int update=0;

        int add=0;

        if(updateList!=nullupdateList.size()0){

         update=medicineService.updateMedicine(updateList);         

        }

        if(addList!=nulladdList.size()0){

         add= medicineService.addMedicine(addList);        

        }

        if(update0||add0){

         return new ResponseModel().attr(ResponseModel.KEY_DATA,"数据导入成功!");

        }else{

         return new ResponseModel().attr(ResponseModel.KEY_ERROR,"数据导入失败!");

        }

} catch (BiffException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

    

    }else{

     return new ResponseModel().attr(ResponseModel.KEY_ERROR,"没有需要导入的数据!");

    }

return null;

}

导出

package beans.excel;

import java.io.IOException;

import java.io.OutputStream;

import java.util.Calendar;

import java.util.Date;

import jxl.Workbook;

import jxl.format.Colour;

import jxl.format.UnderlineStyle;

import jxl.write.Boolean;

import jxl.write.DateFormats;

import jxl.write.DateTime;

import jxl.write.Label;

import jxl.write.Number;

import jxl.write.WritableCellFormat;

import jxl.write.WritableFont;

import jxl.write.WritableSheet;

import jxl.write.WritableWorkbook;

import jxl.write.WriteException;

public class MutiStyleExcelWrite {

    public void createExcel(OutputStream os) throws WriteException,IOException {

        //创建工作薄

        WritableWorkbook workbook = Workbook.createWorkbook(os);

        //创建新的一页

        WritableSheet sheet = workbook.createSheet("First Sheet", 0);

        //构造表头

        sheet.mergeCells(0, 0, 4, 0);//添加合并单元格,第一个参数是起始列,第二个参数是起始行,第三个参数是终止列,第四个参数是终止行

        WritableFont bold = new WritableFont(WritableFont.ARIAL,10,WritableFont.BOLD);//设置字体种类和黑体显示,字体为Arial,字号大小为10,采用黑体显示

        WritableCellFormat titleFormate = new WritableCellFormat(bold);//生成一个单元格样式控制对象

        titleFormate.setAlignment(jxl.format.Alignment.CENTRE);//单元格中的内容水平方向居中

        titleFormate.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);//单元格的内容垂直方向居中

        Label title = new Label(0,0,"JExcelApi支持数据类型详细说明",titleFormate);

        sheet.setRowView(0, 600, false);//设置第一行的高度

        sheet.addCell(title);

        

        //创建要显示的具体内容

        WritableFont color = new WritableFont(WritableFont.ARIAL);//选择字体

        color.setColour(Colour.GOLD);//设置字体颜色为金黄色

        WritableCellFormat colorFormat = new WritableCellFormat(color);

        Label formate = new Label(0,1,"数据格式",colorFormat);

        sheet.addCell(formate);

        Label floats = new Label(1,1,"浮点型");

        sheet.addCell(floats);

        Label integers = new Label(2,1,"整型");

        sheet.addCell(integers);

        Label booleans = new Label(3,1,"布尔型");

        sheet.addCell(booleans);

        Label dates = new Label(4,1,"日期格式");

        sheet.addCell(dates);

        

        Label example = new Label(0,2,"数据示例",colorFormat);

        sheet.addCell(example);

        //浮点数据

        //设置下划线

        WritableFont underline= new WritableFont(WritableFont.ARIAL,WritableFont.DEFAULT_POINT_SIZE,WritableFont.NO_BOLD,false,UnderlineStyle.SINGLE);

        WritableCellFormat greyBackground = new WritableCellFormat(underline);

        greyBackground.setBackground(Colour.GRAY_25);//设置背景颜色为灰色

        Number number = new Number(1,2,3.1415926535,greyBackground);

        sheet.addCell(number);

        //整形数据

        WritableFont boldNumber = new WritableFont(WritableFont.ARIAL,10,WritableFont.BOLD);//黑体

        WritableCellFormat boldNumberFormate = new WritableCellFormat(boldNumber);

        Number ints = new Number(2,2,15042699,boldNumberFormate);

        sheet.addCell(ints);

        //布尔型数据

        Boolean bools = new Boolean(3,2,true);

        sheet.addCell(bools);

        //日期型数据

        //设置黑体和下划线

        WritableFont boldDate = new WritableFont(WritableFont.ARIAL,WritableFont.DEFAULT_POINT_SIZE,WritableFont.BOLD,false,UnderlineStyle.SINGLE);

        WritableCellFormat boldDateFormate = new WritableCellFormat(boldDate,DateFormats.FORMAT1);

        Calendar c = Calendar.getInstance();

        Date date = c.getTime();

        DateTime dt = new DateTime(4,2,date,boldDateFormate);

        sheet.addCell(dt);

        //把创建的内容写入到输出流中,并关闭输出流

        workbook.write();

        workbook.close();

        os.close();

        

    }

}

如何用java将数据库中的表导出到excel

第一步:如何用POI操作Excel

@Test

public void createXls() throws Exception{

//声明一个工作薄

HSSFWorkbook wb = new HSSFWorkbook();

//声明表

HSSFSheet sheet = wb.createSheet("第一个表");

//声明行

HSSFRow row = sheet.createRow(7);

//声明列

HSSFCell cel = row.createCell(3);

//写入数据

cel.setCellValue("你也好");

FileOutputStream fileOut = new FileOutputStream("d:/a/b.xls");

wb.write(fileOut);

fileOut.close();

}

第二步:导出指定数据库的所有表

分析:

1:某个数数据库有多少表,表名是什么?―――DataBaseMetadate.getMetadate().getTables(null,null,null,new String[]{Table}); - excel的文件名称。

2:对每一个表进行select * 操作。 - 每一个sheet的名称。

3:分析表结构,rs.getMetadate(); ResultSetMedated

4:多个列,列名是什么.- 字段名就是sheet的第一行信息。

5:获取每一行的数据 – 放到sheet第一行以后。

@Test

public void export() throws Exception{

//声明需要导出的数据库

String dbName = "focus";

//声明book

HSSFWorkbook book = new HSSFWorkbook();

//获取Connection,获取db的元数据

Connection con = DataSourceUtils.getConn();

//声明statemen

Statement st = con.createStatement();

//st.execute("use "+dbName);

DatabaseMetaData dmd = con.getMetaData();

//获取数据库有多少表

ResultSet rs = dmd.getTables(dbName,dbName,null,new String[]{"TABLE"});

//获取所有表名 - 就是一个sheet

ListString tables = new ArrayListString();

while(rs.next()){

String tableName = rs.getString("TABLE_NAME");

tables.add(tableName);

}

for(String tableName:tables){

HSSFSheet sheet = book.createSheet(tableName);

//声明sql

String sql = "select * from "+dbName+"."+tableName;

//查询数据

rs = st.executeQuery(sql);

//根据查询的结果,分析结果集的元数据

ResultSetMetaData rsmd = rs.getMetaData();

//获取这个查询有多少行

int cols = rsmd.getColumnCount();

//获取所有列名

//创建第一行

HSSFRow row = sheet.createRow(0);

for(int i=0;icols;i++){

String colName = rsmd.getColumnName(i+1);

//创建一个新的列

HSSFCell cell = row.createCell(i);

//写入列名

cell.setCellValue(colName);

}

//遍历数据

int index = 1;

while(rs.next()){

row = sheet.createRow(index++);

//声明列

for(int i=0;icols;i++){

String val = rs.getString(i+1);

//声明列

HSSFCell cel = row.createCell(i);

//放数据

cel.setCellValue(val);

}

}

}

con.close();

book.write(new FileOutputStream("d:/a/"+dbName+".xls"));

}

Java程序中怎么实现报表导入导出功能?

这是finereport报表软件的导入报表过程:

读取某一路径下的模板cpt文件,并将其转为WorkBook对象,有两种读取报表的

方法:一、直接以文件绝对路径读取;二、先定义报表运行环境,然后从运行环

境中直接读取相对路径下的模板。

1.1 绝对路径读取模板

// 读取模板

File cptfile = new File("C:\\FineReport6.5\\WebReport\WEB-

INF\\reportlets\\gettingstarted.cpt");

TemplateImporter tplimp = new TemplateImporter();

WorkBook workbook = tplimp.generateTemplate(cptfile);

1.2 读取报表运行环境下的模板

//定义报表运行环境,读取环境下的报表

String envPath = " C:\\FineReport6.5\\WebReport \\WEB-INF";

FRContext.setCurrentEnv(new LocalEnv(envPath));

TemplateWorkBook workbook = FRContext.getCurrentEnv

().readTemplate("gettingstarted.cpt");

更多的你可以去官网下载一个设计器,去二次开发文档里面看看。

JAVA如何实现导出大数量EXCEL报表 数据大概100W条

好像是你的excel文件问题,你另外新建一个,再写点东西在里面试下随便给你一个我以前用过的importjava.io.*;importjava.text.SimpleDateFormat;importjava.util.*;importjava.sql.*;importjava.util.Date;importjava.util.HashMap;importjava.util.Map;importjxl.*;publicclassSimUpdate{privateStringfileName;publicSimUpdate(StringfileName){this.fileName=fileName;}staticMaptNames;static{tNames=newHashMap();}//下面是主要代码privatevoidupdateDb(){try{Connectionconn=DbPool.connectDB();if(conn!=null){Statementstmt=conn.createStatement();/**********************************************/jxl.Workbookrwb=null;try{//构建Workbook对象只读Workbook对象//直接从本地文件创建Workbook//从输入流创建WorkbookInputStreamis=newFileInputStream(fileName);rwb=Workbook.getWorkbook(is);//Sheet(术语:工作表)就是Excel表格左下角的Sheet ,Sheet ,Sheet 但在程序中//Sheet的下标是从 开始的//获取第一张Sheet表Sheetrs=rwb.getSheet( );//获取Sheet表中所包含的总列数intrsColumns=rs.getColumns();//获取Sheet表中所包含的总行数intrsRows=rs.getRows();//获取指这下单元格的对象引用StringsimNumber="",termSeqId="";//指定SIM卡号及序列号for(inti= ;i ){System.out.println("成功插入第"+i+"条数据");}}}//以下代码为写入新的EXCEL,这里不使用,所以注释/*//利用已经创建的Excel工作薄创建新的可写入的Excel工作薄jxl.write.WritableWorkbookwwb=Workbook.createWorkbook(newFile("D://Book .xls"),rwb);//读取第一张工作表jxl.write.WritableSheetws=wwb.getSheet( );//获取第一个单元格对象jxl.write.WritableCellwc=ws.getWritableCell( , );//决断单元格的类型,做出相应的转化if(wc.getType()==CellType.LABEL){Labell=(Label)wc;l.setString("Thevaluehasbeenmodified.");}//写入Excel对象wwb.write();wwb.close();*/}catch(Exceptione){e.printStackTrace();}finally{//操作完成时,关闭对象,翻译占用的内存空间rwb.close();}/*********************************************/}}catch(Exceptione){e.printStackTrace();}}}

JAVA怎么进行报表导出的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java实现导出excel报表、JAVA怎么进行报表导出的信息别忘了在本站进行查找喔。

The End

发布于:2022-11-22,除非注明,否则均为首码项目网原创文章,转载请注明出处。