資料匯出Excel表 資料庫資料匯出

2021-09-01 19:37:47 字數 2147 閱讀 4102

public static hashmapcolumn = new hashmap();

static

/*** 

* @param table 要匯出的表

* @param name  匯出的excel表名稱、表頭

* @throws exception

*/public void createexcel(string table, string name) throws exception

//excel**

writableworkbook book = workbook.createworkbook(new file(path));

writablesheet sheet = book.createsheet("sheet1", 0);

//整體**樣式

writablecellformat format = new writablecellformat();

format.setalignment(alignment.centre);

format.setverticalalignment(verticalalignment.centre);

format.setwrap(false);

//**標題樣式

writablecellformat titleformat = new writablecellformat();

titleformat.setalignment(alignment.centre);

titleformat.setverticalalignment(verticalalignment.centre);

titleformat.setwrap(false);

writablefont font = new writablefont(writablefont.arial, 15, writablefont.bold);

titleformat.setfont(font);

//**表頭樣式

writablecellformat columnformat = new writablecellformat();

columnformat.setalignment(alignment.centre);

columnformat.setverticalalignment(verticalalignment.centre);

columnformat.setwrap(false);

writablefont columnfont = new writablefont(writablefont.arial, 10, writablefont.bold);

columnformat.setfont(columnfont);

//設定**根據內容多少自動擴容

cellview view = new cellview();

view.setautosize(true);

//獲取資料庫連線,根據你自己的系統情況獲取相應資料庫連線

connection conn = getsession().connection();

preparedstatement ps = conn.preparestatement("select * from " + table + "");

resultset set = ps.executequery();

//獲取列屬性:列數、列名稱

resultsetmetadata meta = set.getmetadata();

int columncount = meta.getcolumncount();

for (int i = 1; i <= columncount; i++)

sheet.mergecells(0, 0, columncount - 1, 1);

label title = new label(0, 0, name, titleformat);

sheet.addcell(title);

int amount = 3;

while(set.next())

amount++;

}// 寫入資料並關閉檔案

book.write();

book.close();

}catch (runtimeexception e)

}

sql匯出資料庫表結構Excel

use sbase 庫名 select 表名 case when a.colorder 1 then d.name else end,表說明 case when a.colorder 1 then isnull f.value,else end,字段序號 a.colorder,欄位名 a.name,...

excel表資料存入資料庫

參考 實現 public string add httpservletrequest request,httpservletresponse response else if file.matches i xlsx sheet sheet workbook.getsheetat 0 sheet 從0...

poi將資料庫資料匯出excel檔案

poi將資料庫資料匯出excel檔案 excel文件 sheet row cell 單元格 hssworkbook hssfsheet hssfrow hssfcell 所有版本poi 3.8 20120326.zip 匯入所需jar包,根目錄和lib目錄下 示例 如下 writing a new ...