本文整理匯總了Java中org.apache.poi.xssf.usermodel.XSSFSheet.getFirstRowNum方法的典型用法代碼示例。如果您正苦於以下問題:Java XSSFSheet.getFirstRowNum方法的具體用法?Java XSSFSheet.getFirstRowNum怎麽用?Java XSSFSheet.getFirstRowNum使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.poi.xssf.usermodel.XSSFSheet
的用法示例。
在下文中一共展示了XSSFSheet.getFirstRowNum方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: readXlsx
import org.apache.poi.xssf.usermodel.XSSFSheet; //導入方法依賴的package包/類
public static ArrayList readXlsx(String path) throws IOException {
XSSFWorkbook xwb = new XSSFWorkbook(path);
XSSFSheet sheet = xwb.getSheetAt(0);
XSSFRow row;
String[] cell = new String[sheet.getPhysicalNumberOfRows() + 1];
ArrayList<String> arrayList = new ArrayList<>();
for (int i = sheet.getFirstRowNum() + 1; i < sheet.getPhysicalNumberOfRows(); i++) {
cell[i] = "";
row = sheet.getRow(i);
for (int j = row.getFirstCellNum(); j < row.getPhysicalNumberOfCells(); j++) {
cell[i] += row.getCell(j).toString();
cell[i] += " | ";
}
arrayList.add(cell[i]);
}
return arrayList;
}
示例2: copySheets
import org.apache.poi.xssf.usermodel.XSSFSheet; //導入方法依賴的package包/類
/**
* @param newSheet the sheet to create from the copy.
* @param sheet the sheet to copy.
* @param copyStyle true copy the style.
*/
public static void copySheets(XSSFSheet newSheet, XSSFSheet sheet, boolean copyStyle) {
int maxColumnNum = 0;
Map<Integer, XSSFCellStyle> styleMap = (copyStyle) ? new HashMap<Integer, XSSFCellStyle>() : null;
for (int i = sheet.getFirstRowNum(); i <= sheet.getLastRowNum(); i++) {
XSSFRow srcRow = sheet.getRow(i);
XSSFRow destRow = newSheet.createRow(i);
if (srcRow != null) {
Util.copyRow(sheet, newSheet, srcRow, destRow, styleMap);
if (srcRow.getLastCellNum() > maxColumnNum) {
maxColumnNum = srcRow.getLastCellNum();
}
}
}
for (int i = 0; i <= maxColumnNum; i++) {
newSheet.setColumnWidth(i, sheet.getColumnWidth(i));
}
//Util.copyPictures(newSheet,sheet) ;
}
示例3: copySheets2CSV
import org.apache.poi.xssf.usermodel.XSSFSheet; //導入方法依賴的package包/類
public static void copySheets2CSV(XSSFSheet sheet, String csvfile) {
int maxColumnNum = 0;
Map<Integer, XSSFCellStyle> styleMap = null;
try {
FileWriter fw = new FileWriter(csvfile);
String str = "";
for (int i = sheet.getFirstRowNum(); i <= sheet.getLastRowNum(); i++) {
XSSFRow srcRow = sheet.getRow(i);
if (srcRow != null) {
System.out.println(srcRow.getLastCellNum());
System.out.println(srcRow.getFirstCellNum());
// System.out.println(srcRow.getCell(srcRow.getLastCellNum()).toString());
for (int j = srcRow.getFirstCellNum(); j < srcRow.getLastCellNum(); j++) {
if (srcRow.getCell(j)!=null&&j != srcRow.getLastCellNum()-1) {
srcRow.getCell(j).setCellType(1);
str = str +srcRow.getCell(j).getReference()+ ",";
} else if(srcRow.getCell(j)!=null){
srcRow.getCell(j).setCellType(1);
str = str +srcRow.getCell(j).getStringCellValue()+ "\r\n";
}
//
}
fw.append(str);
}
str = "";
}
fw.flush();
fw.close();
} catch (IOException ex) {
}//Util.copyPictures(newSheet,sheet) ;
}