java中把SQL数据库中的表导出到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格式导入定单");
}
}
如何将sql 2005 表里数据导出到excel
对于会写查询
SQL语句
的则是直查询语句查询出。如下图:
接下来到桌面一个空的excel文件。
接下来回到
SQLServer
查询界面。鼠标右键点击查询结果的左上角空白列,点击“连同标题一起复制”。则已复制好了数据。如下图:
接下来打开之前建好的Excel文件把复制好的数据黏贴到excel即可。如下图:
如何导出oracle数据库中某张表到excel
如何导oracle数据库中某张表到excel
无法直接到excel中,但是可以保存到csv,同样是excel的格式,方法如下:
譬如要把文件生成在d盘下的test目录下:
1,在d盘根目录下新建test目录 2,sqlplus以system用sysdba登录3,create or replace directory TMP as ’d:\test’;4,grant read on directory TMP to user; 5,alter system set utl_file_dir='d:\test' scope=spfile;
然后建立存储过程,表是随便建了一个,最后的文件名按要求需要按照当前日期的前一天生成,所以后边文件名的地方write_file_name处就按照要求来了
sql语句将数据库表中的数据导出到excel,怎么操作??
首先要确定SQL语句的。以下是VB里的数据导出代码,已假设了一个adodc控件:
Dim i, j As Integer
Dim ex As Object
Dim exwbook As Object
Dim exsheet As Object
Set ex = CreateObject("Excel.Application") '创建EXCEL对象
Set exwbook = ex.Workbooks.Add '打开文件
ex.Visible = True
Set exsheet = exwbook.Worksheets("sheet1") '设定工作表
With Adodc1.Recordset
For j = 2 To .Fields.Count
exsheet.Cells(1, 1) = "序号"
exsheet.Cells(1, j) = .Fields(j - 1).Name
Next
.MoveFirst
For i = 1 To .RecordCount
For j = 2 To .Fields.Count
exsheet.Cells(i 1, 1) = i
exsheet.Cells(i 1, j) = .Fields(j - 1).Value
Next
.MoveNext
Next i
End With
如何将数据库的表导出生成Excel
方法一:对于会写SQL语句的则是直查询语询出结果。如下图:
接下来到桌面新建空的excel文件。
接下来回到SQLServer查询界面。鼠标右键点击查询结果的左上角空白列,点击“连同标题一起复制”。则已复制好了数据。如下图:
接下来打开之前建好的Excel文件把复制好的数据黏贴到excel即可。如下图:
方法二:对于不会写查询SQL语句的则使用数据库导出方法。
选中要导出数据的数据库,点击右键会弹出一个右键菜单。点击“任务”再点击“导出数据(x)”。如下图:
点击了“导出数据(x)”后会弹出一个界面,并填写好信息。如下图:
点击下一步跳转到如下图1中的界面。在目标中选中excel类型,界面信息则发生改变,并选中导出的excel路径。如下图2。
点击下一步跳转至如下界面,选中第一个选项。如下图:
点击下一步,勾选要导出的表。如下图:
点击下一步,跳转至如下界面:
点击下一步:跳转到如下图1界面,选择下一步在点击完成,则会跳到如下图2界面。证明已经导出成功了。
打开excel就可用看到导出的Excel了。如下图: