问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

如何把java查询出的内容导入到excel表格

发布网友 发布时间:2022-04-20 19:10

我来回答

1个回答

热心网友 时间:2023-07-14 14:19

java查询出的内容导入到excel表格
/**导出数据为XLS格式
* @param fos
* @param bo
*/
public void writeExcelBo(FileOutputStream fos, java.util.Vector ve)
{
jxl.write.WritableWorkbook wwb;
try
{
wwb= Workbook.createWorkbook(fos);
jxl.write.WritableSheet ws= wwb.createSheet("booksheet", 10);
ws.addCell(new jxl.write.Label(0, 1, "书目ID"));
ws.addCell(new jxl.write.Label(1, 1, "ISBN"));
ws.addCell(new jxl.write.Label(2, 1, "定价"));
ws.addCell(new jxl.write.Label(3, 1, "书名"));
ws.addCell(new jxl.write.Label(4, 1, "原书名"));
ws.addCell(new jxl.write.Label(5, 1, "副题名"));
ws.addCell(new jxl.write.Label(6, 1, "著者"));
ws.addCell(new jxl.write.Label(7, 1, "译者"));
ws.addCell(new jxl.write.Label(8, 1, "版次"));
ws.addCell(new jxl.write.Label(9, 1, "出版地"));
ws.addCell(new jxl.write.Label(10, 1, "出版社"));
ws.addCell(new jxl.write.Label(11, 1, "出版日期"));
ws.addCell(new jxl.write.Label(12, 1, "页数"));
ws.addCell(new jxl.write.Label(13, 1, "书高"));
ws.addCell(new jxl.write.Label(14, 1, "装帧"));
ws.addCell(new jxl.write.Label(15, 1, "丛书名"));
ws.addCell(new jxl.write.Label(16, 1, "一般性附注项"));
ws.addCell(new jxl.write.Label(17, 1, "简介"));
ws.addCell(new jxl.write.Label(18, 1, "主题词"));
ws.addCell(new jxl.write.Label(19, 1, "中图法分类"));
ws.addCell(new jxl.write.Label(20, 1, "更新日期"));
ws.addCell(new jxl.write.Label(21, 1, "本数"));
book=new Book[ve.size()];
for (int i= 0; i < ve.size(); i++)
{
book[i]= (Book)ve.get(i);
ws.addCell(new jxl.write.Label(0, i + 2, "" + book[i].getBookId()));
ws.addCell(new jxl.write.Label(1, i + 2, book[i].getIsbn()));
ws.addCell(new jxl.write.Label(2, i + 2, "" + book[i].getPrice()));
ws.addCell(new jxl.write.Label(3, i + 2, book[i].getBookTitle()));
ws.addCell(new jxl.write.Label(4, i + 2, book[i].getOldFilename()));
ws.addCell(new jxl.write.Label(5, i + 2, book[i].getSubTitle()));
ws.addCell(new jxl.write.Label(6, i + 2, book[i].getWriter()));
ws.addCell(new jxl.write.Label(7, i + 2, book[i].getTranscribe()));
ws.addCell(new jxl.write.Label(8, i + 2, "" + book[i].getVersion()));
ws.addCell(new jxl.write.Label(9, i + 2, book[i].getPublishCity()));
ws.addCell(new jxl.write.Label(10, i + 2, book[i].getPublisher()));
ws.addCell(new jxl.write.Label(11, i + 2, book[i].getPublishDate().toString()));
ws.addCell(new jxl.write.Label(12, i + 2, "" + book[i].getPage()));
ws.addCell(new jxl.write.Label(13, i + 2, "" + book[i].getHight()));
ws.addCell(new jxl.write.Label(14, i + 2, book[i].getInstall()));
ws.addCell(new jxl.write.Label(15, i + 2, book[i].getSeries()));
ws.addCell(new jxl.write.Label(16, i + 2, book[i].getNotes()));
ws.addCell(new jxl.write.Label(17, i + 2, book[i].getPrecisnotes()));
ws.addCell(new jxl.write.Label(18, i + 2, book[i].getSubject()));
ws.addCell(new jxl.write.Label(19, i + 2, book[i].getCls().replaceAll("_", "")));
ws.addCell(new jxl.write.Label(20, i + 2, book[i].getUpdatedate().toString()));
ws.addCell(new jxl.write.Label(21, i + 2, "0"));
}
jxl.write.WritableFont wfc=
new jxl.write.WritableFont(
WritableFont.ARIAL,
255,
WritableFont.BOLD,
false,
UnderlineStyle.NO_UNDERLINE,
jxl.format.Colour.BLACK);
jxl.write.WritableCellFormat wcfFC= new jxl.write.WritableCellFormat(wfc);
ws.addCell(new jxl.write.Label(0, 0, "为保证您提交定单的稳定和正确,导入定单时候请勿更改此表格式(请勿更改书目ID,订购本数自行添加!)"));
wwb.write();
//关闭Excel工作薄对象
wwb.close();
} catch (IOException e)
{} catch (RowsExceededException e)
{} catch (WriteException e)
{}
}

//导入EXCEL
if (f.getName().indexOf(".xls") > 0)
{
try
{
fis= new FileInputStream(f);
BookBean bob= new BookBean();
UserBean usb= new UserBean();
jxl.Workbook rwb= Workbook.getWorkbook(fis);
jxl.Sheet sh= rwb.getSheet(0);
int rowCount= sh.getRows();
SimpleDateFormat sdf= new SimpleDateFormat("dd/MM/yyyy");
book= new Book[rowCount - 1];
for (int i= 1; i < rowCount; i++)
{
book[i - 1]= new Book();
jxl.Cell[] ce= sh.getRow(i);
book[i - 1].setIsbn(ce[0].getContents().toString());
book[i - 1].setSeries(ce[1].getContents().toString());
book[i - 1].setBookTitle(ce[2].getContents().toString());
book[i - 1].setWriter(ce[3].getContents().toString());
book[i - 1].setTranscribe(ce[4].getContents().toString());
book[i - 1].setPublisher(ce[5].getContents().toString());
book[i - 1].setPublishDate(sdf.parse(ce[6].getContents().toString(), new ParsePosition(0)));
book[i-1].setVersion(Integer.parseInt(ce[7].getContents().toString()));
book[i-1].setPage(Integer.parseInt(ce[8].getContents().toString()));
book[i-1].setCls(ce[9].getContents().toString());
book[i-1].setPrecisnotes(ce[10].getContents().toString());
book[i-1].setInstall(ce[11].getContents().toString());
book[i-1].setPrice(Float.parseFloat(ce[12].getContents().toString()));
book[i-1].setUserid(usb.getUser().getUserid());
getVector().addElement(book[i - 1]);
}
rwb.close();
fis.close();
} catch (FileNotFoundException e)
{} catch (BiffException e)
{} catch (IOException e)
{} catch (NumberFormatException e)
{
ShowMessage("数据导入失败,请按照本软件要求的EXCEL格式导入定单");
}
}
声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
八月中国最凉快的地方 八月份哪里最凉快,去哪旅游好?美丽的地方 乱字同韵字是什么意思 华硕笔记本电脑触摸板怎么开笔记本电脑触摸板怎么开启和关闭_百度知 ... 陕西职务侵占案立案准则 结婚后我的恋情维系了十年,怎么做到的? 玉米仁子饭产自哪里 中国期货交易所的交易品种有哪些? 历史要怎么读,有啥诀窍 高中历史诀窍 java怎么批量导入excel数据 急!高手进,关于java导入excel的问题! 如何在java中导入导出excel 如何在java程序中导入excel数据 java导入excel怎么导入? 我手机的新浪微博为出现错误代码怎么办 新浪微博错误代码c502 如何解决 水晶杯与玻璃杯 北京名烟名酒回收教您如何鉴别杯子... 水晶杯跟玻璃杯有什么区别?要怎么分辨?拜托了各... 为什么要用水晶杯而不是玻璃杯,两者的区别是什么? 水晶玻璃杯和普通玻璃杯的区别 水晶杯与玻璃杯的区别在那里,如何识别 你好,水晶杯和玻璃杯的区别? 水晶杯跟玻璃杯有什么区别?要怎么分辨? 微博账号异常,代码3022608什么意思? 汽车空调内部怎么清洗 汽车空调有必要清洗吗? 汽车空调系统如何清洗? 汽车空调清洁的步骤有哪些? 最近途虎的“驾驰空调养护“三大冷器”广告做的很大,... java 中怎么从excel中导入数据 如何用java导入excel数据到数据库 怎样利用java实现把数据自动导入excel? java web 怎么导入excel文件 java如何将数据导入Excel模板 java中如何导入Excel,并给出模板 java poi怎么导入excel数据 java开发怎么导入导出excel里面信息内容? java excel poi 怎么导入 如何把excel数据导入java 日利率0.045,一万一天多少钱 借一万,日利息0.03%,一个月利息多少 日利率0.065.10000元一年是多少钱? 一万块日利息0.07一个月多少钱啊利息。 日利息0.18怎么算?比如一万那一个月又是多少 为什么借10000日利率0.065一年的利息是1000多? 借一万日利率5.5是多少? 借10000日利率0.034一个月多少利息是多少? 10000元日利息0.55一个月多少利息 日利率一万是4.5一千元日利率是多少?