![]() |
| 點選要匯出的資料表 |
![]() |
| 點選"進階"->選僅限資料 |
![]() |
| 選擇要匯出到哪裡 |
![]() |
| 開始匯出 |
![]() |
| 匯出完成,可以insert到其他DB |
try {
String original_filename = "fileToOutput.xls";
String sRealPath = (String) original_filename;
//產生要存的excel
File file = new File(sRealPath);
//產生一檔案WritableWorkbook讓程式匯出
WritableWorkbook writableWorkBook = Workbook.createWorkbook(file);
//在檔案中開啟一新的sheet
WritableSheet writableSheet = writableWorkBook.createSheet("我是第一張sheet", 1);
//WritableSheet writableSheet2 = writableWorkBook.createSheet("我是第二張sheet", 2);
//設定寫入儲存格的字型大小
WritableFont chFont12w = new WritableFont(WritableFont.createFont("Times New Roman"), 12);
WritableCellFormat writableCellFormat = new WritableCellFormat(chFont12w);
//label中的(0,0)代表excel中的(A,0)
//label中的(1,0)代表excel中的(B,0)
//label中的(1,1)代表excel中的(B,1),以此類推
Label deptLabel = new Label(0, 0, "印出字串",writableCellFormat);
writableSheet.addCell(deptLabel);
//寫入EXCEL檔案
writableWorkBook.write();
//關閉檔案
writableWorkBook.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
NTCredentials creds = new NTCredentials("帳", "密", "", "網域");
httpclient.getCredentialsProvider().setCredentials(AuthScope.ANY, creds);
HttpPost httppost = new HttpPost("上傳目標位置");
httpclient.getParams().setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET,"UTF-8");
httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION,HttpVersion.HTTP_1_1);
FileBody bin = new FileBody(new File(sourcePath),"","UTF-8");
StringBody title = new StringBody(fileName,Charset.forName("UTF-8"));
MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE,null,Charset.forName("UTF-8"));
reqEntity.addPart("file", bin);
reqEntity.addPart("fileTitle", title);
httppost.setEntity(reqEntity);
HttpResponse response = httpclient.execute(httppost);
EntityUtils.consume(resEntity);
try {
httpclient.getConnectionManager().shutdown();
} catch (Exception ee) {ee.printStackTrace(); }
if ("fileTitle".equals(item.getFieldName())) {
fileTitle = new String(item.getString().getBytes("ISO-8859-1"), "UTF-8");
}
originalFileName = item.getName();
System.out.println("originalFileName:"+originalFileName);