java代码导入ppt java怎么导入( 二 )


if (null != workbook.getSheetAt(numSheets)) {
XSSFSheet aSheet = workbook.getSheetAt(numSheets);// 获得一个sheet
for (int rowNumOfSheet = 0; rowNumOfSheet = aSheet
.getLastRowNum(); rowNumOfSheet++) {
if (null != aSheet.getRow(rowNumOfSheet)) {
XSSFRow aRow = aSheet.getRow(rowNumOfSheet); // 获得一个行
for (short cellNumOfRow = 0; cellNumOfRow = aRow
.getLastCellNum(); cellNumOfRow++) {
if (null != aRow.getCell(cellNumOfRow)) {
XSSFCell aCell = aRow.getCell(cellNumOfRow);// 获得列值
if (this.convertCell(aCell).length()0) {
content.append(this.convertCell(aCell));
}
}
content.append("\n");
}
}
}
}
}
return content.toString();
}
private String convertCell(Cell cell) {
NumberFormat formater = NumberFormat.getInstance();
formater.setGroupingUsed(false);
String cellValuehttps://www.04ip.com/post/= "";
if (cell == null) {
return cellValue;
}
switch (cell.getCellType()) {
case HSSFCell.CELL_TYPE_NUMERIC:
cellValue = https://www.04ip.com/post/formater.format(cell.getNumericCellValue());
break;
case HSSFCell.CELL_TYPE_STRING:
cellValue = https://www.04ip.com/post/cell.getStringCellValue();
break;
case HSSFCell.CELL_TYPE_BLANK:
cellValue = https://www.04ip.com/post/cell.getStringCellValue();
break;
case HSSFCell.CELL_TYPE_BOOLEAN:
cellValue = https://www.04ip.com/post/Boolean.valueOf(cell.getBooleanCellValue()).toString();
break;
case HSSFCell.CELL_TYPE_ERROR:
cellValue = https://www.04ip.com/post/String.valueOf(cell.getErrorCellValue());
break;
default:
cellValuehttps://www.04ip.com/post/= "";
}
return cellValue.trim();
}
// 读取pdf文件
public String readPDF(String file) throws IOException {
String result = null;
FileInputStream is = null;
PDDocument document = null;
try {
is = new FileInputStream(file);
PDFParser parser = new PDFParser(is);
parser.parse();
document = parser.getPDDocument();
PDFTextStripper stripper = new PDFTextStripper();
result = stripper.getText(document);
} finally {
if (is != null) {
is.close();
}
if (document != null) {
document.close();
}
}
return result;
}
// 读取doc文件
public String readWORD(String file) throws Exception {
String returnStr = "";
try {
WordExtractor wordExtractor = new WordExtractor(new FileInputStream(new File(file)));
returnStr = wordExtractor.getText();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return returnStr;
}
// 读取docx文件
public String readWORD2007(String file) throws Exception {
return new XWPFWordExtractor(POIXMLDocument.openPackage(file)).getText();
}
// 读取txt文件
public String readTXT(String file) throws IOException {
String encoding = ReadFileUtils.get_charset(new File(file));
if (encoding.equalsIgnoreCase("GBK")) {
return FileUtils.readFileToString(new File(file), "gbk");
} else {
return FileUtils.readFileToString(new File(file), "utf8");
}
}
private static String get_charset(File file) throws IOException {
String charset = "GBK";
byte[] first3Bytes = new byte[3];
BufferedInputStream bis = null;
try {
boolean checked = false;
bis = new BufferedInputStream(new FileInputStream(file));
bis.mark(0);
int read = bis.read(first3Bytes, 0, 3);
if (read == -1)
return charset;
if (first3Bytes[0] == (byte) 0xFFfirst3Bytes[1] == (byte) 0xFE) {
charset = "UTF-16LE";
checked = true;
} else if (first3Bytes[0] == (byte) 0xFE

推荐阅读