本文整理匯總了Java中jxl.write.WritableWorkbook.getSheet方法的典型用法代碼示例。如果您正苦於以下問題:Java WritableWorkbook.getSheet方法的具體用法?Java WritableWorkbook.getSheet怎麽用?Java WritableWorkbook.getSheet使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類jxl.write.WritableWorkbook
的用法示例。
在下文中一共展示了WritableWorkbook.getSheet方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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());
}
}
示例2: 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;
}
示例3: writeGoldStandard
import jxl.write.WritableWorkbook; //導入方法依賴的package包/類
protected void writeGoldStandard(List<Dataset> datasets, Dataset goldStandard) throws Exception {
WorkbookSettings settings = new WorkbookSettings();
settings.setEncoding("iso8859-1");
WorkbookSettings settings2 = new WorkbookSettings();
settings2.setEncoding("utf8");
Workbook w = Workbook.getWorkbook(datasetInfo.getOriginalAnnotationFile(), settings);
WritableWorkbook workbook = Workbook.createWorkbook(datasetInfo.getGoldStandardFile(), w/*, settings2*/);
WritableSheet sheet = workbook.getSheet(0);
CellFormat annotationCell = sheet.getColumnView(10).getFormat();
int itemCount = datasets.get(0).countAnnotations();
for (int itemIdx = 0; itemIdx < itemCount; itemIdx++) {
Integer annot = goldStandard.getAnnotationValue(itemIdx);
int rowIdx = datasets.get(0).getAnnotation(itemIdx).getLine();
CellFormat format = sheet.getWritableCell(10, rowIdx).getCellFormat();
if (format == null)
format = annotationCell;
if (annot != null && annot >= 0)
sheet.addCell(new jxl.write.Number(10, rowIdx, annot,
format));
}
workbook.write();
workbook.close();
w.close();
}
示例4: addItem
import jxl.write.WritableWorkbook; //導入方法依賴的package包/類
public void addItem(Path file, boolean newSheet) throws FileNotFoundException,
IOException,
BiffException,
WriteException {
//Get the existing excel file
Workbook workbook = Workbook.getWorkbook(excelFile);
// Open a copy of the excel file,and specify the parameters
// to write the data back to the original file.
WritableWorkbook writeBook = Workbook.createWorkbook(excelFile, workbook);
// writable sheet
WritableSheet sheet = null;
// new or append
if (newSheet) {
// remove exist
writeBook.removeSheet(0);
// create new sheet
sheet = writeBook.createSheet("default sheet", 0);
// reset row number
rows = 0;
} else {
// get the sheet of zero
sheet = writeBook.getSheet(0);
// update rows
rows = sheet.getRows();
}
// add the name and the path
Label lable0 = new Label(0, rows, file.getFileName().toString());
sheet.addCell(lable0);
Label lable1 = new Label(1, rows, file.toString());
sheet.addCell(lable1);
//Write the workbook in file system
writeBook.write();
// close the file
writeBook.close();
}
示例5: expMainFile
import jxl.write.WritableWorkbook; //導入方法依賴的package包/類
/**
* 單個主表的數據替換,生成excel
* @param templetFile 模板文件
* @param mainData 主表
* @param outFile 指定輸出的excel文件全路徑
* @return 返回輸出文件對象
* @throws Exception
* @throws IOException
*/
public static File expMainFile(String templetFile,Map mainData,String outFile) throws Exception, IOException{
File f=new File(outFile); //輸出的文件
Workbook workbook = Workbook.getWorkbook(new File(templetFile));//獲取操作Workbook
WritableWorkbook excelbook = Workbook.createWorkbook(f, workbook);//複製一個模板,並進行編輯模板
WritableSheet wtsh = excelbook.getSheet(0);
ExcelUitl.updateReadOneCell(wtsh, mainData); //更新 主信息
excelbook.write();
excelbook.close();
return f;
}
示例6: exportExcelByModulex11
import jxl.write.WritableWorkbook; //導入方法依賴的package包/類
/**
* @deprecated
* @param dataMap
* @param outExcelName
* @param url
* @return
*/
public File exportExcelByModulex11(HashMap dataMap, String outExcelName,
String url) {
File f = new File(outExcelName);//模板路徑
try {
Workbook workbook = Workbook.getWorkbook(new File(url));//獲取操作Workbook
WritableWorkbook excelbook = Workbook.createWorkbook(f, workbook);//編輯模板
WritableSheet sheet2 = excelbook.getSheet(0);
int controlNo = 0;
int startNo = -1;
String mapString = "";
for (int r = 0; r < sheet2.getRows(); r++) {
for (int c = 0; c < sheet2.getColumns(); c++) {
// System.out.println(" (r,c): -- "+"(r="+r+" c="+c+")");
WritableCell cell = sheet2.getWritableCell(c, r);//可編輯單元格
if (cell.getType() == CellType.EMPTY)
continue;
Label lb = (Label) cell;
String signName = lb.getString().trim();
// System.out.println("-signName- > : "+signName);
if (dataMap.containsKey(signName)
&& signName.indexOf("AGGREGATE_START") > -1) {
controlNo++;
startNo = r;
mapString = signName;
} else if (dataMap.containsKey(signName)) {
controlNo++;
lb.setString(dataMap.get(signName).toString());
}
if (controlNo == dataMap.size()) {
r = sheet2.getRows();
c = sheet2.getColumns();
} else if (cell.getContents().equals("[ORVER]")) {
r = sheet2.getRows();
c = sheet2.getColumns();
lb.setString("");
}
}
}
// ArrayList ma = (ArrayList) dataMap.get(mapString);
// if (ma != null && ma.size() > 0 && !mapString.equals(""))
// sheet2 = this.autoAddRowExcel2_XX(sheet2, ma, startNo, 5);
// else if (startNo > -1)
// sheet2.removeRow(startNo);
excelbook.write();
excelbook.close();
} catch (Exception e) {
throw new RuntimeException("寫入文件失敗。", e);
} finally {
//System.out.println("導出完成---Excel");
}
return f;
}
示例7: exportExcelByModulex11
import jxl.write.WritableWorkbook; //導入方法依賴的package包/類
public File exportExcelByModulex11(HashMap dataMap, String outExcelName,
String url) {
File f = new File(outExcelName);//模板路徑
try {
Workbook workbook = Workbook.getWorkbook(new File(url));//獲取操作Workbook
WritableWorkbook excelbook = Workbook.createWorkbook(f, workbook);//編輯模板
WritableSheet sheet2 = excelbook.getSheet(0);
int controlNo = 0;
int startNo = -1;
String mapString = "";
for (int r = 0; r < sheet2.getRows(); r++) {
for (int c = 0; c < sheet2.getColumns(); c++) {
// System.out.println(" (r,c): -- "+"(r="+r+" c="+c+")");
WritableCell cell = sheet2.getWritableCell(c, r);//可編輯單元格
if (cell.getType() == CellType.EMPTY)
continue;
Label lb = (Label) cell;
String signName = lb.getString().toUpperCase().trim();
// System.out.println("-signName- > : "+signName);
if (dataMap.containsKey(signName)
&& signName.indexOf("AGGREGATE_START") > -1) {
controlNo++;
startNo = r;
mapString = signName;
} else if (dataMap.containsKey(signName)) {
controlNo++;
lb.setString(dataMap.get(signName).toString());
}
if (controlNo == dataMap.size()) {
r = sheet2.getRows();
c = sheet2.getColumns();
} else if (cell.getContents().equals("[ORVER]")) {
r = sheet2.getRows();
c = sheet2.getColumns();
lb.setString("");
}
}
}
ArrayList ma = (ArrayList) dataMap.get(mapString);
if (ma != null && ma.size() > 0 && !mapString.equals(""))
sheet2 = this.autoAddRowExcel2_XX(sheet2, ma, startNo, 5);
else if (startNo > -1)
sheet2.removeRow(startNo);
excelbook.write();
excelbook.close();
} catch (Exception e) {
throw new RuntimeException("寫入文件失敗。", e);
} finally {
//System.out.println("導出完成---Excel");
}
return f;
}
示例8: getErrorAnnotatedWorkbook
import jxl.write.WritableWorkbook; //導入方法依賴的package包/類
public WritableWorkbook getErrorAnnotatedWorkbook()
{
try {
BufferedOutputStream dummyOutputStream = new BufferedOutputStream(new ByteArrayOutputStream());
WritableWorkbook errorAnnotatedWorkbook = jxl.Workbook.createWorkbook(dummyOutputStream);
if (_workbook != null) {
errorAnnotatedWorkbook = jxl.Workbook.createWorkbook(dummyOutputStream);
errorAnnotatedWorkbook.importSheet(ScreenResultWorkbookSpecification.DATA_COLUMNS_SHEET_NAME,
1,
_workbook.getWorkbook().getSheet(ScreenResultWorkbookSpecification.DATA_COLUMNS_SHEET_NAME));
}
// annotate workbook with non-cell-specific error by appending to a specially created "errors" sheet
for (WorkbookParseError error : _errors) {
if (error.getCell() == null) {
WritableSheet generalParseErrorsSheet = errorAnnotatedWorkbook.getSheet("Parse Errors");
if (generalParseErrorsSheet == null) {
generalParseErrorsSheet = errorAnnotatedWorkbook.createSheet("Parse Errors", 0);
}
generalParseErrorsSheet.addCell(new Label(0, generalParseErrorsSheet.getRows(), error.getErrorMessage()));
}
else {
Sheet parsedSheet = error.getCell().getSheet();
WritableSheet errorAnnotatedSheet = errorAnnotatedWorkbook.getSheet(parsedSheet.getName());
if (errorAnnotatedSheet == null) {
errorAnnotatedSheet = errorAnnotatedWorkbook.importSheet(parsedSheet.getName(),
Integer.MAX_VALUE,
parsedSheet);
}
annotateCellWithError(error.getCell().getJxlCell(),
errorAnnotatedSheet,
error);
}
}
return errorAnnotatedWorkbook;
}
catch (Exception e) {
log.error(e);
e.printStackTrace();
return null;
}
}