本文整理匯總了Java中org.apache.poi.hssf.usermodel.HSSFRow.createCell方法的典型用法代碼示例。如果您正苦於以下問題:Java HSSFRow.createCell方法的具體用法?Java HSSFRow.createCell怎麽用?Java HSSFRow.createCell使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.poi.hssf.usermodel.HSSFRow
的用法示例。
在下文中一共展示了HSSFRow.createCell方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: makeHeader
import org.apache.poi.hssf.usermodel.HSSFRow; //導入方法依賴的package包/類
private void makeHeader ( final List<Field> columns, final HSSFSheet sheet )
{
final Font font = sheet.getWorkbook ().createFont ();
font.setFontName ( "Arial" );
font.setBoldweight ( Font.BOLDWEIGHT_BOLD );
font.setColor ( HSSFColor.WHITE.index );
final CellStyle style = sheet.getWorkbook ().createCellStyle ();
style.setFont ( font );
style.setFillForegroundColor ( HSSFColor.BLACK.index );
style.setFillPattern ( PatternFormatting.SOLID_FOREGROUND );
final HSSFRow row = sheet.createRow ( 0 );
for ( int i = 0; i < columns.size (); i++ )
{
final Field field = columns.get ( i );
final HSSFCell cell = row.createCell ( i );
cell.setCellValue ( field.getHeader () );
cell.setCellStyle ( style );
}
}
示例2: insertItemToSheet
import org.apache.poi.hssf.usermodel.HSSFRow; //導入方法依賴的package包/類
private void insertItemToSheet(String table, HSSFSheet sheet, ArrayList<String> columns) {
HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
Cursor cursor = database.rawQuery("select * from " + table, null);
cursor.moveToFirst();
int n = 1;
while (!cursor.isAfterLast()) {
HSSFRow rowA = sheet.createRow(n);
for (int j = 0; j < columns.size(); j++) {
HSSFCell cellA = rowA.createCell(j);
if (cursor.getType(j) == Cursor.FIELD_TYPE_BLOB) {
HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0, (short) j, n, (short) (j + 1), n + 1);
anchor.setAnchorType(3);
patriarch.createPicture(anchor, workbook.addPicture(cursor.getBlob(j), HSSFWorkbook.PICTURE_TYPE_JPEG));
} else {
cellA.setCellValue(new HSSFRichTextString(cursor.getString(j)));
}
}
n++;
cursor.moveToNext();
}
cursor.close();
}
示例3: writeXLSFile
import org.apache.poi.hssf.usermodel.HSSFRow; //導入方法依賴的package包/類
public static void writeXLSFile() throws IOException {
HSSFWorkbook wbObj = new HSSFWorkbook();
HSSFSheet sheet = wbObj.createSheet(sheetName);
for (int row = 0; row < tableData.size(); row++) {
HSSFRow rowObj = sheet.createRow(row);
rowData = tableData.get(row);
for (int col = 0; col < rowData.size(); col++) {
HSSFCell cellObj = rowObj.createCell(col);
cellObj.setCellValue(rowData.get(col));
}
}
FileOutputStream fileOut = new FileOutputStream(excelFileName);
wbObj.write(fileOut);
wbObj.close();
fileOut.flush();
fileOut.close();
}
示例4: createColumnHeaders
import org.apache.poi.hssf.usermodel.HSSFRow; //導入方法依賴的package包/類
/**
*/
protected void createColumnHeaders() {
final HSSFRow headersRow = this.sheet.createRow(0);
final HSSFFont font = this.workbook.createFont();
font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
final HSSFCellStyle style = this.workbook.createCellStyle();
style.setFont(font);
style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
int counter = 1;
for (int i = 0; i < this.model.getColumnCount(); i++) {
final HSSFCell cell = headersRow.createCell(counter++);
// cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(this.model.getColumnName(i));
cell.setCellStyle(style);
}
}
示例5: createContent
import org.apache.poi.hssf.usermodel.HSSFRow; //導入方法依賴的package包/類
public void createContent(WebInput wi, DocInfo di)throws ControllerException {
HSSFWorkbook wb = di.getExcelDocument();
// 創建HSSFSheet對象
HSSFSheet sheet = wb.createSheet("sheet0");
// 創建HSSFRow對象
HSSFRow row = sheet.createRow((short) 0);
// 創建HSSFCell對象
HSSFCell cell = row.createCell((short) 0);
// 用來處理中文問題
// cell.setEncoding(HSSFCell.ENCODING_UTF_16);
// 設置單元格的值
// cell.setCellValue("Hello World! 你好,中文世界");
String info = wi.getParameter("info");
HSSFRichTextString rts = new HSSFRichTextString(info);
cell.setCellValue(rts);
HSSFCell cell2 = row.createCell((short) 1);
cell2.setCellValue(new HSSFRichTextString(
"Beetle Web Framework 頁麵生成Excel文件演示!"));
}
示例6: writeBody
import org.apache.poi.hssf.usermodel.HSSFRow; //導入方法依賴的package包/類
void writeBody(HSSFSheet sheet){
Set<String> keySet = getColumnJson().keySet();
List<T> ts = getData();
for (T t:ts) {
// Class cls = t.getClass();
int cellNumber = 0;//將cellNumber從0開始
HSSFRow row = sheet.createRow(addRowNumber());//創建新的一行
for(String key:keySet){
try {
HSSFCell cell = row.createCell(cellNumber++);
Object value = getValueByKey(t, key);
setCellValue(cell, value);
pubMaxValue(key, value);
} catch (Exception e) {
throw new RuntimeException("writeBody", e);
}
}
}
}
示例7: createHeader
import org.apache.poi.hssf.usermodel.HSSFRow; //導入方法依賴的package包/類
private boolean createHeader(WorkbookGeneratorContext context,
HSSFSheet sheet,
HSSFCellStyle style) {
if (context.headerNames == null || context.headerNames.isEmpty()) {
return false;
}
int headerRowIndex = 0;
HSSFRow rowHeader = sheet.createRow(headerRowIndex);
for (int i = 0; i < context.headerNames.size(); i++) {
HSSFCell cell = rowHeader.createCell(i);
sheet.autoSizeColumn((short) i);
cell.setCellStyle(style);
cell.setCellValue(new HSSFRichTextString(context.headerNames.get(i)));
}
return true;
}
示例8: writeDirectTestData
import org.apache.poi.hssf.usermodel.HSSFRow; //導入方法依賴的package包/類
@Override
protected void writeDirectTestData(final ERTable table, final Map<NormalColumn, String> data, final String database) {
final HSSFRow row = sheet.createRow(rowNum++);
int col = 0;
for (final NormalColumn column : table.getExpandedColumns()) {
final HSSFCell cell = row.createCell(col++);
final String value = Format.null2blank(data.get(column));
if (value == null || "null".equals(value.toLowerCase())) {
} else {
cell.setCellValue(new HSSFRichTextString(value));
}
}
}
示例9: write
import org.apache.poi.hssf.usermodel.HSSFRow; //導入方法依賴的package包/類
public void write(String src) throws IOException{
System.out.println(src);
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("Resultats");
for (int i=0; i<size(); i++) {
HSSFRow row = sheet.createRow(i);
HSSFCell cell = row.createCell(0);
cell.setCellValue(get(i).area());
}
FileOutputStream fileOut;
fileOut = new FileOutputStream(src);
wb.write(fileOut);
fileOut.close();
}
示例10: writeCondtions
import org.apache.poi.hssf.usermodel.HSSFRow; //導入方法依賴的package包/類
/**
* 表頭條件
* @param sheet
* @param t
* @param cellCount
* @return
*/
void writeCondtions(HSSFSheet sheet){
T t = getConditions();
if (t!=null) {
HSSFRow row = sheet.createRow(getRowNumber());
row.setHeight((short) 500);
CellRangeAddress cra = new CellRangeAddress(getRowNumber(), getRowNumber(), 0, getColumnJson().size());
sheet.addMergedRegion(cra);
HSSFCell cell = row.createCell(0);
HSSFCellStyle style = cell.getCellStyle();
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
style.setWrapText(true);
cell.setCellStyle(style);
setCellValue(cell, formatCondition(t));
addRowNumber();
}
}
示例11: test_001
import org.apache.poi.hssf.usermodel.HSSFRow; //導入方法依賴的package包/類
@Test
public void test_001()
{
HSSFWorkbook v_Workbook = new HSSFWorkbook();
HSSFSheet v_Sheet = v_Workbook.createSheet("測試單元格顏色");
v_Sheet.setColumnWidth(0 ,2560);
for (int v_RowIndex=0; v_RowIndex<4000; v_RowIndex++)
{
HSSFRow v_Row = v_Sheet.createRow(v_RowIndex);
for (int v_ColIndex=0; v_ColIndex<1; v_ColIndex++)
{
HSSFCell v_Cell = v_Row.createCell(v_ColIndex);
HSSFCellStyle v_CellStyle = v_Workbook.createCellStyle();
v_CellStyle.setFillForegroundColor((short)(v_RowIndex + 1));
v_CellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
v_Cell.setCellStyle(v_CellStyle);
v_Cell.setCellValue("" + (v_RowIndex + 1));
}
}
ExcelHelp.save(v_Workbook ,"/Users/hy/Downloads/測試2003版本的單元格顏色");
}
示例12: createSheet
import org.apache.poi.hssf.usermodel.HSSFRow; //導入方法依賴的package包/類
private void createSheet(String table, HSSFSheet sheet) {
HSSFRow rowA = sheet.createRow(0);
ArrayList<String> columns = getColumns(table);
for (int i = 0; i < columns.size(); i++) {
HSSFCell cellA = rowA.createCell(i);
cellA.setCellValue(new HSSFRichTextString("" + columns.get(i)));
}
insertItemToSheet(table, sheet, columns);
}
示例13: writeTableHeader
import org.apache.poi.hssf.usermodel.HSSFRow; //導入方法依賴的package包/類
@Override
protected void writeTableHeader(final ERDiagram diagram, final ERTable table) {
final String sheetName = table.getPhysicalName();
sheet = workbook.createSheet(sheetName);
rowNum = 0;
final HSSFRow row = sheet.createRow(rowNum++);
int col = 0;
for (final NormalColumn column : table.getExpandedColumns()) {
final HSSFCell cell = row.createCell(col++);
cell.setCellValue(new HSSFRichTextString(column.getPhysicalName()));
}
}
示例14: createHeader
import org.apache.poi.hssf.usermodel.HSSFRow; //導入方法依賴的package包/類
private void createHeader(
HSSFWorkbook wb,
HSSFSheet sheet,
List<TascaDadaDto> informeCamps) {
HSSFFont bold;
bold = wb.createFont();
bold.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
bold.setColor(HSSFColor.WHITE.index);
HSSFCellStyle headerStyle;
headerStyle = wb.createCellStyle();
headerStyle.setFillPattern(HSSFCellStyle.FINE_DOTS);
headerStyle.setFillBackgroundColor(HSSFColor.GREY_80_PERCENT.index);
headerStyle.setFont(bold);
int rowNum = 0;
int colNum = 0;
// Capçalera
HSSFRow xlsRow = sheet.createRow(rowNum++);
HSSFCell cell;
cell = xlsRow.createCell(colNum++);
cell.setCellValue(new HSSFRichTextString(StringUtils.capitalize("Expedient")));
cell.setCellStyle(headerStyle);
for (TascaDadaDto camp : informeCamps) {
sheet.autoSizeColumn(colNum);
cell = xlsRow.createCell(colNum++);
cell.setCellValue(new HSSFRichTextString(StringUtils.capitalize(camp.getCampEtiqueta())));
cell.setCellStyle(headerStyle);
}
}
示例15: getCell
import org.apache.poi.hssf.usermodel.HSSFRow; //導入方法依賴的package包/類
/**
* Convenient method to obtain the cell in the given sheet, row and column.
* <p>Creates the row and the cell if they still doesn't already exist.
* Thus, the column can be passed as an int, the method making the needed downcasts.
* @param sheet a sheet object. The first sheet is usually obtained by workbook.getSheetAt(0)
* @param row the row number
* @param col the column number
* @return the HSSFCell
*/
protected HSSFCell getCell(HSSFSheet sheet, int row, int col) {
HSSFRow sheetRow = sheet.getRow(row);
if (sheetRow == null) {
sheetRow = sheet.createRow(row);
}
HSSFCell cell = sheetRow.getCell(col);
if (cell == null) {
cell = sheetRow.createCell(col);
}
return cell;
}