本文整理汇总了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) ;
}