本文整理汇总了Java中jxl.write.WritableSheet.mergeCells方法的典型用法代码示例。如果您正苦于以下问题:Java WritableSheet.mergeCells方法的具体用法?Java WritableSheet.mergeCells怎么用?Java WritableSheet.mergeCells使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jxl.write.WritableSheet
的用法示例。
在下文中一共展示了WritableSheet.mergeCells方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createExcelSheet
import jxl.write.WritableSheet; //导入方法依赖的package包/类
public void createExcelSheet(WritableSheet excelSheet) {
int row, col;
// Create cells
for (row=0; row<nrows; row++)
for (col=0; col<ncolumns[row]; col++) {
if (sheet[row][col]==null)
continue;
try {
if (sheet[row][col].getMerge_to_col()>=0 && sheet[row][col].getMerge_to_row()>=0)
excelSheet.mergeCells(col, row, sheet[row][col].getMerge_to_col(), sheet[row][col].getMerge_to_row());
switch (sheet[row][col].getType()) {
case LABEL:
excelSheet.addCell(new Label(col,row,sheet[row][col].getString(),getExcelFormat(row, col)));
break;
case FLOAT:
case INTEGER:
excelSheet.addCell(new Number(col,row,sheet[row][col].getNumber(),getExcelFormat(row, col)));
break;
case IMAGE:
File f = new File(sheet[row][col].getString());
WritableImage imgobj=new WritableImage(col, row, sheet[row][col].getWidth(), sheet[row][col].getHeight(), f);
excelSheet.addImage(imgobj);
break;
case VOID:
break;
case FORMULA:
excelSheet.addCell( new Formula(col, row, sheet[row][col].getString(),getExcelFormat(row, col)) );
break;
default:
break;
}
} catch (WriteException we) {};
}
// Resize columns
for (col=0; colSize!=null && col<colSize.length; col++)
if (colSize[col]>0)
excelSheet.setColumnView(col, colSize[col]);
}
示例2: rowSpan
import jxl.write.WritableSheet; //导入方法依赖的package包/类
/**
* 合并单元格(行合并),合并规则:内容相同则合并
*
* @param sheet 合并的sheet
* @param colindex 合并列索引
* @param contentBeginIndex 正文开始行
* @return
*/
@SuppressWarnings("deprecation")
public static WritableSheet rowSpan(WritableSheet sheet, int colindex, int contentBeginIndex) throws Exception {
// 总行数
int rowNum = sheet.getRows();
Cell[] cells = sheet.getRow(1);
// 正文内容应该从第二行开始,第一行为表头的标题
int startRow = contentBeginIndex;
String startValue = "";
for (int i = contentBeginIndex; i <= rowNum; i++) {
cells = sheet.getRow(i);
String value = cells[colindex].getContents();
if (i == contentBeginIndex) {
startValue = value;
continue;
}
if (StrUtil.isNotBlank(startValue) && StrUtil.isNotBlank(value) && startValue.equals(value)) {
if (i == rowNum) //sheet.mergeCells(int col1,int row1,int col2,int row2);//左上角到右下角
sheet.mergeCells(colindex,startRow, colindex,i);
else
continue;
} else {
if((i-1)>startRow)
sheet.mergeCells(colindex,startRow, colindex,i - 1);
startRow = i;
}
startValue=value;
}
return sheet;
}
示例3: outputHelp
import jxl.write.WritableSheet; //导入方法依赖的package包/类
/**
* @param workSheet to add the help to
* @param table to fetch metadata from
* @param startRow to start adding rows at
* @param helpTextRowNumbers - map to insert row numbers for each help field into
* @return the index of the next row to use
* @throws WriteException if any of the writes to workSheet failed
*/
private int outputHelp(WritableSheet workSheet, Table table, final int startRow, final Map<String, Integer> helpTextRowNumbers) throws WriteException {
int currentRow = startRow;
// Title for the descriptions
Label dataLabel = new Label(0, currentRow, "Column Descriptions");
dataLabel.setCellFormat(getBoldFormat());
workSheet.addCell(dataLabel);
currentRow++;
int currentColumn = 0;
for (Column column : table.columns()) {
if (!column.getName().equals("id") && !column.getName().equals("version")) {
// Field name to go with the description
Label fieldName = new Label(0, currentRow, spreadsheetifyName(column.getName()));
fieldName.setCellFormat(getBoldFormat());
workSheet.addCell(fieldName);
// The type/width
String typeString = column.getType() + "(" + column.getWidth() + (column.getScale() == 0 ? "" : "," + column.getScale()) + ")";
Label fieldType = new Label(1, currentRow, typeString);
fieldType.setCellFormat(getStandardFormat());
workSheet.addCell(fieldType);
// The default
String defaultValue = additionalSchemaData.columnDefaultValue(table, column.getName());
Label fieldDefault = new Label(2, currentRow, defaultValue);
fieldDefault.setCellFormat(getStandardFormat());
workSheet.addCell(fieldDefault);
// The field documentation
workSheet.mergeCells(3, currentRow, 12, currentRow);
String documentation = additionalSchemaData.columnDocumentation(table, column.getName());
Label documentationLabel = new Label(3, currentRow, documentation);
WritableCellFormat format = new WritableCellFormat(getStandardFormat());
format.setWrap(true);
format.setVerticalAlignment(VerticalAlignment.TOP);
documentationLabel.setCellFormat(format);
workSheet.addCell(documentationLabel);
//If we've exceed the maximum number of columns - then output truncated warnings
if(currentColumn >= MAX_EXCEL_COLUMNS) {
Label truncatedWarning = new Label(13, currentRow, "[TRUNCATED]");
truncatedWarning.setCellFormat(getBoldFormat());
workSheet.addCell(truncatedWarning);
}
// We are aiming for 150px. 1px is 15 Excel "Units"
workSheet.setRowView(currentRow, 150 * 15);
// Remember at what row we created the help text for this column
helpTextRowNumbers.put(column.getName(), currentRow);
currentRow++;
currentColumn++;
}
}
// Group all the help rows together
workSheet.setRowGroup(startRow + 1, currentRow - 1, true);
// Some extra blank space for neatness
currentRow++;
return currentRow;
}
示例4: createSystemSlotSheet
import jxl.write.WritableSheet; //导入方法依赖的package包/类
private void createSystemSlotSheet(WritableSheet sheet) throws RowsExceededException, WriteException {
GenericData slot[];
int row;
int i,j;
String s[];
int lparNameSize=0;
int descriptionSize=0;
int locationSize=0;
row = 0;
for (i=0; i<managedSystem.length; i++) {
/*
* Show start of system
*/
s = managedSystem[i].getVarValues("name");
sheet.mergeCells(0, row, 3, row+1);
addLabel(sheet,0,row,s[0],formatLabel(BOLD|CENTRE|VCENTRE|GREEN));
row++;
row++;
/*
* Setup titles
*/
addLabel(sheet,0,row,"LPAR",formatLabel(BOLD|B_ALL_MED));
addLabel(sheet,1,row,"Adapter description",formatLabel(BOLD|B_ALL_MED));
addLabel(sheet,2,row,"Location",formatLabel(BOLD|B_ALL_MED));
addLabel(sheet,3,row,"drc_index",formatLabel(CENTRE|BOLD|B_ALL_MED));
row ++;
/*
* Write variables
*/
slot = managedSystem[i].getObjects(SLOT);
if (slot==null) {
row +=2;
continue;
}
for (j=0; j<slot.length; j++) {
s = slot[j].getVarValues("lpar_name");
if (s!=null) {
addLabel(sheet, 0, row, s, 0, formatLabel(B_LEFT_LOW|B_BOTTOM_LOW|B_RIGHT_LOW));
if (s[0].length()>lparNameSize)
lparNameSize=s[0].length();
} else
addLabel(sheet, 0, row, null, 0, formatLabel(B_LEFT_LOW|B_BOTTOM_LOW|B_RIGHT_LOW));
s = slot[j].getVarValues("description");
addLabel(sheet, 1, row, s, 0, formatLabel(B_LEFT_LOW|B_BOTTOM_LOW|B_RIGHT_LOW));
if (s[0].length()>descriptionSize)
descriptionSize=s[0].length();
s = slot[j].getVarValues("drc_name");
addLabel(sheet, 2, row, s, 0, formatLabel(B_LEFT_LOW|B_BOTTOM_LOW|B_RIGHT_LOW));
if (s[0].length()>locationSize)
locationSize=s[0].length();
s = slot[j].getVarValues("drc_index");
addLabel(sheet, 3, row, s, 0, formatLabel(CENTRE|B_LEFT_LOW|B_BOTTOM_LOW|B_RIGHT_LOW));
row++;
}
row +=2;
}
if (lparNameSize < 10)
lparNameSize=8;
sheet.setColumnView(0, lparNameSize+2);
sheet.setColumnView(1, descriptionSize+2);
sheet.setColumnView(2, locationSize+2);
sheet.setColumnView(3, 10);
}
示例5: createSysRAMUsageSheet
import jxl.write.WritableSheet; //导入方法依赖的package包/类
private void createSysRAMUsageSheet(WritableSheet sheet) throws RowsExceededException, WriteException {
int i,j;
String s;
float f,f2;
int size=0;
int row;
String timeLabels[] = msMemConfig[0].getMonthlyLabels();
row = 0;
sheet.mergeCells(0, row, 13, row);
addLabel(sheet,0,row,"Average Free Memory GB",formatLabel(BOLD|CENTRE|VCENTRE|GREEN));
sheet.mergeCells(15, row, 28, row);
addLabel(sheet,15,row,"Average Percentage Free Memory",formatLabel(BOLD|CENTRE|VCENTRE|GREEN));
row++;
for (i=0; i<timeLabels.length; i++) {
s = timeLabels[i];
addLabel(sheet,1+i,row,s,formatLabel(BOLD|B_ALL_MED));
addLabel(sheet,16+i,row,s,formatLabel(BOLD|B_ALL_MED));
}
row++;
for (i=0; i<managedSystem.length; i++) {
s = managedSystem[i].getVarValues("name")[0];
if (s.length()>size)
size=s.length();
addLabel(sheet,0,row+i,s,formatLabel(BOLD|VCENTRE|CENTRE|B_ALL_MED));
addLabel(sheet,15,row+i,s,formatLabel(BOLD|VCENTRE|CENTRE|B_ALL_MED));
for (j=0; j<timeLabels.length; j++) {
f = msMemAvail[i].getMonthData(j);
f2 = msMemConfig [i].getMonthData(j);
if (f>=0)
addNumber(sheet,1+j,row+i, f, formatFloat(B_RIGHT_LOW|B_LEFT_LOW|B_BOTTOM_LOW));
if (f>=0 && f2>0)
addNumber(sheet,16+j,row+i, f/f2*100, formatFloat(B_RIGHT_LOW|B_LEFT_LOW|B_BOTTOM_LOW));
}
}
row+=i;
row++;
sheet.mergeCells(0, row, 13, row);
addLabel(sheet,0,row,"Average Configured Memory GB",formatLabel(BOLD|CENTRE|VCENTRE|GREEN));
row++;
for (i=0; i<timeLabels.length; i++) {
s = timeLabels[i];
addLabel(sheet,1+i,row,s,formatLabel(BOLD|B_ALL_MED));
}
row++;
for (i=0; i<managedSystem.length; i++) {
s = managedSystem[i].getVarValues("name")[0];
if (s.length()>size)
size=s.length();
addLabel(sheet,0,row+i,s,formatLabel(BOLD|VCENTRE|CENTRE|B_ALL_MED));
for (j=0; j<timeLabels.length; j++) {
f = msMemConfig [i].getMonthData(j);
if (f>=0)
addNumber(sheet,1+j,row+i, f, formatFloat(B_RIGHT_LOW|B_LEFT_LOW|B_BOTTOM_LOW));
}
}
row+=i;
row++;
sheet.setColumnView(0, size+6);
sheet.setColumnView(15, size+6);
}
示例6: createSysRAMUsageSheet_OLD
import jxl.write.WritableSheet; //导入方法依赖的package包/类
private void createSysRAMUsageSheet_OLD(WritableSheet sheet) throws RowsExceededException, WriteException {
int i,j;
String s;
float f;
int size=0;
int jump;
for (i=1; i<=4; i++)
addLabel(sheet,1+i,0,"Week "+i,formatLabel(BOLD|B_ALL_MED));
for (i=1; i<=12; i++)
addLabel(sheet,6+i,0,"Month "+i,formatLabel(BOLD|B_ALL_MED));
for (i=0; i<managedSystem.length; i++) {
s = managedSystem[i].getVarValues("name")[0];
if (s.length()>size)
size=s.length();
sheet.mergeCells(0, 1+2*i, 0, 2+2*i);
addLabel(sheet,0,1+2*i,s,formatLabel(BOLD|VCENTRE|CENTRE|B_ALL_MED));
addLabel(sheet,1,1+2*i,"Config",formatLabel(BOLD|B_ALL_MED));
addLabel(sheet,1,2+2*i,"Avail",formatLabel(BOLD|B_ALL_MED));
jump=0;
for (j=0; j<NUM_SUMMARY; j++) {
if ( (f=managedSystemDataSummary[i][j][CONFIGURABLE_SYS_MEM])>=0 )
addNumber(sheet,2+j+jump,1+2*i, f, formatInt(B_RIGHT_LOW|B_LEFT_LOW|B_BOTTOM_LOW));
else
addLabel(sheet,2+j+jump,1+2*i, "", formatLabel(B_RIGHT_LOW|B_LEFT_LOW|B_BOTTOM_LOW));
if ( (f=managedSystemDataSummary[i][j][AVAIL_SYS_MEM])>=0 )
addNumber(sheet,2+j+jump,2+2*i, f, formatInt(B_RIGHT_LOW|B_LEFT_LOW|B_BOTTOM_MED));
else
addLabel(sheet,2+j+jump,2+2*i, "", formatInt(B_RIGHT_LOW|B_LEFT_LOW|B_BOTTOM_MED));
if (j==WEEK4) {
jump=1;
}
}
}
sheet.setColumnView(0, size+6);
sheet.setColumnView(6, 2);
}
示例7: createSysPoolUsageSheet_OLD
import jxl.write.WritableSheet; //导入方法依赖的package包/类
private void createSysPoolUsageSheet_OLD(WritableSheet sheet) throws RowsExceededException, WriteException {
int i,j;
String s;
float f;
int size=0;
int jump;
for (i=1; i<=4; i++)
addLabel(sheet,1+i,0,"Week "+i,formatLabel(BOLD|B_ALL_MED));
for (i=1; i<=12; i++)
addLabel(sheet,6+i,0,"Month "+i,formatLabel(BOLD|B_ALL_MED));
for (i=0; i<managedSystem.length; i++) {
s = managedSystem[i].getVarValues("name")[0];
if (s.length()>size)
size=s.length();
sheet.mergeCells(0, 1+3*i, 0, 3+3*i);
addLabel(sheet,0,1+3*i,s,formatLabel(BOLD|VCENTRE|CENTRE|B_ALL_MED));
addLabel(sheet,1,1+3*i,"Config",formatLabel(BOLD|B_ALL_MED));
addLabel(sheet,1,2+3*i,"Avail",formatLabel(BOLD|B_ALL_MED));
addLabel(sheet,1,3+3*i,"Used",formatLabel(BOLD|B_ALL_MED));
jump=0;
for (j=0; j<NUM_SUMMARY; j++) {
if ( (f=managedSystemDataSummary[i][j][CONFIGURABLE_POOL_PROC_UNITS]+managedSystemDataSummary[i][j][BORROWED_POOL_PROC_UNITS])>=0 )
addNumber(sheet,2+j+jump,1+3*i, f, formatInt(B_RIGHT_LOW|B_LEFT_LOW|B_BOTTOM_LOW));
else
addLabel(sheet,2+j+jump,1+3*i, "", formatLabel(B_RIGHT_LOW|B_LEFT_LOW|B_BOTTOM_LOW));
if ( (f=managedSystemDataSummary[i][j][CURR_AVAIL_POOL_PROC_UNITS])>=0 )
addNumber(sheet,2+j+jump,2+3*i, f, formatFloat(B_RIGHT_LOW|B_LEFT_LOW|B_BOTTOM_LOW));
else
addLabel(sheet,2+j+jump,2+3*i, "", formatLabel(B_RIGHT_LOW|B_LEFT_LOW|B_BOTTOM_LOW));
if ( (f=managedSystemDataSummary[i][j][USED_POOL])>=0 )
addNumber(sheet,2+j+jump,3+3*i, f, formatFloat(B_RIGHT_LOW|B_LEFT_LOW|B_BOTTOM_MED));
else
addLabel(sheet,2+j+jump,3+3*i, "", formatLabel(B_RIGHT_LOW|B_LEFT_LOW|B_BOTTOM_MED));
if (j==WEEK4) {
jump=1;
//addLabel(sheet,2+j+jump,3+3*i, "", formatLabel(B_LEFT_LOW|B_RIGHT_LOW|B_LEFT_LOW|B_BOTTOM_MED));
}
}
}
sheet.setColumnView(0, size+6);
sheet.setColumnView(6, 2);
}
示例8: genExcel
import jxl.write.WritableSheet; //导入方法依赖的package包/类
/**
* 生成excel文件
* @param data
* @param out
* @return
* @throws Exception
*/
public void genExcel(List<T> data, OutputStream out) throws Exception{
WritableWorkbook workbook = Workbook.createWorkbook(out);
WritableSheet sheet = workbook.createSheet(getSheetName(), 0);
for(int column = 0; column < 100; column++){
sheet.setColumnView(column, 28);
}
int localStartRow = getStartRow();
if(getTitle()!=null){
sheet.addCell(new Label(startColumn, localStartRow, getTitle(),getTitleCellFormat()));
sheet.mergeCells(startColumn, localStartRow, 7, localStartRow);
localStartRow++;
}
int tempColumnIndex = startColumn;
for(Map.Entry<String, Field> entry : binder.entrySet()){
int tempRowIndex = localStartRow;
sheet.addCell(new Label(tempColumnIndex, tempRowIndex++, entry.getKey(), getHeaderCellFormat()));
for(T t : data){
Object obj = Util.getFieldValue(entry.getValue(), t);
if(obj instanceof Date){
sheet.addCell(new Label(tempColumnIndex, tempRowIndex++, Util.dateToString((Date)obj), getDateCellFormat()));
}else{
sheet.addCell(new Label(tempColumnIndex, tempRowIndex++, obj.toString(), getBodyCellFormat()));
}
}
tempColumnIndex++;
}
workbook.write();
workbook.close();
}