本文整理匯總了Java中jxl.write.WritableWorkbook類的典型用法代碼示例。如果您正苦於以下問題:Java WritableWorkbook類的具體用法?Java WritableWorkbook怎麽用?Java WritableWorkbook使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
WritableWorkbook類屬於jxl.write包,在下文中一共展示了WritableWorkbook類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: readExcel
import jxl.write.WritableWorkbook; //導入依賴的package包/類
public static void readExcel(String inputfileName, String outputfileName) throws BiffException, IOException , RowsExceededException, WriteException{
Workbook wb=Workbook.getWorkbook(new File(inputfileName));
Sheet sheet = wb.getSheet(0); //get sheet(0)
WritableWorkbook wwb = Workbook.createWorkbook(new File(outputfileName));
WritableSheet ws = wwb.createSheet("topicName", 0);
//traversal
for(int i=0; i<sheet.getRows(); i++)
{
String content = sheet.getCell(0,i).getContents();
String[] words = content.split("\\(");
content = words[0];
content = content.toLowerCase();
content = content.replaceAll("_", " ");
content = content.replaceAll("-", " ");
content = content.replaceAll("\\s+", " ");
if(content.contains("data structure") && !content.trim().equals("data structure"))
content = content.replaceAll("data structure", "");
Label labelC = new Label(0, i, content.trim());
ws.addCell(labelC);
}
wwb.write();
wwb.close();
}
示例2: printRows
import jxl.write.WritableWorkbook; //導入依賴的package包/類
private long printRows(XlsExporterContext context, RowWriter writer) throws Throwable {
jobOutput.println("writing to file " + context.getFileName());
try {
WritableWorkbook workbook;
WorkbookSettings workbookSettings = writer.getWorkbookSettings();
if (workbookSettings != null) {
workbook = Workbook.createWorkbook(new File(context.getFileName()), workbookSettings);
} else {
workbook = Workbook.createWorkbook(new File(context.getFileName()));
}
context.setWorkbook(workbook);
writer.init();
writer.printRows();
workbook.write();
workbook.close();
} catch (Exception e) {
throw new IllegalArgumentException("row " + (writer.getLineCount() + 1) + ": error writing row", e);
}
jobOutput.println(writer.getLineCount() + " rows exported");
return writer.getLineCount();
}
示例3: ExportTLDToXLS
import jxl.write.WritableWorkbook; //導入依賴的package包/類
public static void ExportTLDToXLS(String filename, ArrayList<Object> data) throws IOException {
try {
WritableFont titleFont = new WritableFont(WritableFont.ARIAL, 10, WritableFont.BOLD, true);
WritableCellFormat titleformat = new WritableCellFormat(titleFont);
WritableWorkbook workbook = Workbook.createWorkbook(new File(filename));
WritableSheet sheet = workbook.createSheet("TLD Expand", 0);
sheet.addCell(new Label(0, 0, "Domain name", titleformat));
sheet.addCell(new Label(1, 0, "Name server", titleformat));
sheet.addCell(new Label(2, 0, "Admin name", titleformat));
sheet.addCell(new Label(3, 0, "Registrant", titleformat));
int nextRow = 1;
Iterator i = data.iterator();
while (i.hasNext()) {
DomainResult res = (DomainResult) i.next();
sheet.addCell(new Label(0, nextRow, res.getDomainName()));
sheet.addCell(new Label(1, nextRow, res.getNameServer()));
sheet.addCell(new Label(2, nextRow, res.getAdminName()));
sheet.addCell(new Label(3, nextRow, res.getRegistrant()));
nextRow++;
}
workbook.write();
workbook.close();
} catch (WriteException ex) {
Logger.getLogger("resultExport.ExportForwardLookupsToXLS").log(Level.SEVERE, null, ex);
}
}
示例4: ExportCertToXLS
import jxl.write.WritableWorkbook; //導入依賴的package包/類
public static void ExportCertToXLS(String filename, ArrayList<Object> data) throws IOException {
try {
WritableFont titleFont = new WritableFont(WritableFont.ARIAL, 10, WritableFont.BOLD, true);
WritableCellFormat titleformat = new WritableCellFormat(titleFont);
WritableWorkbook workbook = Workbook.createWorkbook(new File(filename));
WritableSheet sheet = workbook.createSheet("SSLCert CN", 0);
sheet.addCell(new Label(0, 0, "IP address", titleformat));
sheet.addCell(new Label(1, 0, "Host name", titleformat));
sheet.addCell(new Label(2, 0, "Domain name", titleformat));
int nextRow = 1;
Iterator i = data.iterator();
while (i.hasNext()) {
CertResult res = (CertResult) i.next();
sheet.addCell(new Label(0, nextRow, res.getIpAddress()));
sheet.addCell(new Label(1, nextRow, res.getHostName()));
sheet.addCell(new Label(2, nextRow, res.getDomainName()));
nextRow++;
}
workbook.write();
workbook.close();
} catch (WriteException ex) {
Logger.getLogger("resultExport.ExportForwardLookupsToXLS").log(Level.SEVERE, null, ex);
}
}
示例5: testUnsupportedColumns
import jxl.write.WritableWorkbook; //導入依賴的package包/類
@Test
public void testUnsupportedColumns() {
TableOutputter outputter = mock(TableOutputter.class);
final SpreadsheetDataSetConsumer consumer =
new SpreadsheetDataSetConsumer(
mock(OutputStream.class),
Optional.<Map<String, Integer>>empty(),
outputter
);
Table one = table("one");
Table two = table("two");
when(outputter.tableHasUnsupportedColumns(one)).thenReturn(true);
when(outputter.tableHasUnsupportedColumns(two)).thenReturn(false);
consumer.table(one, NO_RECORDS);
consumer.table(two, NO_RECORDS);
verify(outputter).table(anyInt(), any(WritableWorkbook.class), eq(two), eq(NO_RECORDS));
verify(outputter, times(0)).table(anyInt(), any(WritableWorkbook.class), eq(one), eq(NO_RECORDS));
}
示例6: createWorkbook
import jxl.write.WritableWorkbook; //導入依賴的package包/類
/**
* 創建 Excel Workbook
* @param object 傳入 File對象 或者是 OutputStream對象
* @return
*/
public static WritableWorkbook createWorkbook(Object object){
WritableWorkbook wbook = null;
try {
if (object instanceof File) {
File file = (File) object;
// 建立excel文件
wbook = Workbook.createWorkbook(file);
} else if (object instanceof OutputStream) {
OutputStream os = (OutputStream) object;
// 建立excel文件
wbook = Workbook.createWorkbook(os);
} else {
throw new IllegalArgumentException("Please input File Object or OutputStream Object.");
}
} catch (IOException e) {
e.printStackTrace();
}
return wbook;
}
示例7: export
import jxl.write.WritableWorkbook; //導入依賴的package包/類
/**
* @param parameter
* @param stream
* @throws IOException
* @throws WriteException
*/
public void export(CalculationParameter a_objParameter, ByteArrayOutputStream a_objStream) throws IOException, WriteException
{
this.m_objParameter = a_objParameter;
WritableWorkbook t_objWorkbook = Workbook.createWorkbook(a_objStream);
WritableSheet t_objSheet = t_objWorkbook.createSheet("Settings", 0);
this.formatSettingsPage(t_objSheet);
this.createSettingSheet(t_objSheet);
t_objSheet = t_objWorkbook.createSheet("Results", 1);
this.formatResultPage(t_objSheet);
this.createResultSheet(t_objSheet);
t_objSheet.setPageSetup(PageOrientation.LANDSCAPE);
t_objWorkbook.write();
t_objWorkbook.close();
}
示例8: writeIntoFile
import jxl.write.WritableWorkbook; //導入依賴的package包/類
private void writeIntoFile(File target) {
WritableWorkbook targetBook = null;
try {
WorkbookSettings workbookSettings = new WorkbookSettings();
workbookSettings.setEncoding("ISO-8859-1");
targetBook = Workbook.createWorkbook(target, workbookSettings);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (targetBook != null) {
writeIntoWorkbook(targetBook);
} else {
System.err.println("Failed to get workbook!");
}
}
示例9: writeList
import jxl.write.WritableWorkbook; //導入依賴的package包/類
public void writeList(String[] data) throws FileNotFoundException,
IOException,
WriteException {
//Blank workbook
WritableWorkbook workbook = Workbook.createWorkbook(excelFile);
//Create a blank sheet
WritableSheet sheet = workbook.createSheet("defaut sheet", 0);
//Iterate over data and write to sheet
int rownum = 0;
for (String str : data) {
// create a colum cell
Label label0 = new Label(0, rownum, Paths.get(str).getFileName().toString());
sheet.addCell(label0);
Label label1 = new Label(1, rownum, str);
sheet.addCell(label1);
}
//Write the workbook in file system
workbook.write();
// close the file
workbook.close();
}
示例10: exportXls
import jxl.write.WritableWorkbook; //導入依賴的package包/類
public static void exportXls(SortedMap<java.lang.Number, java.lang.Number> data, String filePath) {
File file = new File(filePath);
WorkbookSettings workBookSettings = new WorkbookSettings();
workBookSettings.setLocale(LOCALE);
try {
WritableWorkbook workbook = Workbook.createWorkbook(file, workBookSettings);
workbook.createSheet("Exported data", 0);
WritableSheet sheet = workbook.getSheet(0);
fillSheet(sheet, data);
workbook.write();
workbook.close();
} catch (IOException | WriteException exception) {
System.err.println(exception.getMessage());
}
}
示例11: exportExcelByModulex1
import jxl.write.WritableWorkbook; //導入依賴的package包/類
public File exportExcelByModulex1( String outExcelName,
String url) {
File f = new File(outExcelName);//輸出文件
try {
Workbook workbook = Workbook.getWorkbook(new File(url));//獲取模板
WritableWorkbook excelbook = Workbook.createWorkbook(f, workbook);//編輯模板
WritableSheet sheet2 = excelbook.getSheet(0);//編輯第一個Sheet
//sheet2 = this.copyExcelRows(sheet2,12,10,2,2);
sheet2 = this.copyExcelRows(sheet2,12,10,2,1);
excelbook.write();
excelbook.close();
} catch (Exception e) {
throw new RuntimeException("寫入文件失敗。", e);
} finally {
//System.out.println("導出完成---Excel");
}
return f;
}
示例12: writeToExcel
import jxl.write.WritableWorkbook; //導入依賴的package包/類
/**
* 寫出到excel
*/
public String writeToExcel() {
String result = null;
//
WritableWorkbook workBook = null;
try {
String excelName = excelName(WuxingCollector.class);
File file = new File(excelName);
workBook = Workbook.createWorkbook(file);
// 資料
writeToSheet_0(workBook);
// 常數
writeToSheet_1(workBook);
//
workBook.write();
//
result = excelName;
} catch (Exception ex) {
throw new EditorException(ex);
} finally {
close(workBook);
}
//
return result;
}
示例13: writeToExcel
import jxl.write.WritableWorkbook; //導入依賴的package包/類
public String writeToExcel() {
String result = null;
//
WritableWorkbook workBook = null;
try {
String excelName = excelName(WuxingCollector.class);
File file = new File(excelName);
workBook = Workbook.createWorkbook(file);
// 資料
writeToSheet_0(workBook);
// 常數
writeToSheet_1(workBook);
//
workBook.write();
//
result = excelName;
} catch (Exception ex) {
throw new EditorException(ex);
} finally {
close(workBook);
}
//
return result;
}
示例14: writeToExcel
import jxl.write.WritableWorkbook; //導入依賴的package包/類
public String writeToExcel() {
String result = null;
//
WritableWorkbook workBook = null;
try {
String excelName = excelName(TrainCollector.class);
File file = new File(excelName);
workBook = Workbook.createWorkbook(file);
// 資料
writeToSheet_0(workBook);
// 常數
writeToSheet_1(workBook);
//
workBook.write();
//
result = excelName;
} catch (Exception ex) {
throw new EditorException(ex);
} finally {
close(workBook);
}
//
return result;
}
示例15: writeToExcel
import jxl.write.WritableWorkbook; //導入依賴的package包/類
public String writeToExcel() {
String result = null;
//
WritableWorkbook workBook = null;
try {
String excelName = excelName(QixingCollector.class);
File file = new File(excelName);
workBook = Workbook.createWorkbook(file);
// 資料
// writeToSheet_0(result);
// 常數
// writeToSheet_1(result);
//
//workBook.write();
//
result = excelName;
} catch (Exception ex) {
throw new EditorException(ex);
} finally {
close(workBook);
}
//
return result;
}