日期:2014-05-17  浏览次数:20718 次

java中把SQL数据库中的表导出到excel中.怎么实现
我用的eclipse软件做的.上面有个combo下拉控键连接数据表.下面是一个button控键来导出数据表到excel表中.怎么来使用实现button备份combo中选中的数据表? 
新人.请高人指点.(具体语句最好!!)谢谢.

------解决方案--------------------
SQL code
前段时间正好做了,导入和导出的,你自己看吧
 /**导出数据为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, "为保证您提交定单的稳定和正确,导入定单时候请勿更改此表格