java poi 怎样读取excel中插入的文本框中的内容
1个回答
展开全部
参考代码如下:
try {
InputStream input = new FileInputStream("qa-textbox.xls");
POIFSFileSystem fs = new POIFSFileSystem(input);
HSSFWorkbook wb = new HSSFWorkbook(fs);
HSSFSheet sheet = wb.getSheetAt(0);
HSSFPatriarch pat = sheet.getDrawingPatriarch();
List children = pat.getChildren();
Iterator it = children.iterator();
while(it.hasNext()) {
HSSFShape shape = (HSSFShape)it.next();
if (shape instanceof HSSFTextbox){ //判断文本框
HSSFTextbox textbox = (HSSFTextbox)shape;//强转成textbox类型
HSSFRichTextString richString = textbox.getString(); //取值。。
String str = richString.getString();
System.out.println("String: " + str);
System.out.println("String length: " + str.length());
}
}
} catch (IOException ex) {
ex.printStackTrace();
}
try {
InputStream input = new FileInputStream("qa-textbox.xls");
POIFSFileSystem fs = new POIFSFileSystem(input);
HSSFWorkbook wb = new HSSFWorkbook(fs);
HSSFSheet sheet = wb.getSheetAt(0);
HSSFPatriarch pat = sheet.getDrawingPatriarch();
List children = pat.getChildren();
Iterator it = children.iterator();
while(it.hasNext()) {
HSSFShape shape = (HSSFShape)it.next();
if (shape instanceof HSSFTextbox){ //判断文本框
HSSFTextbox textbox = (HSSFTextbox)shape;//强转成textbox类型
HSSFRichTextString richString = textbox.getString(); //取值。。
String str = richString.getString();
System.out.println("String: " + str);
System.out.println("String length: " + str.length());
}
}
} catch (IOException ex) {
ex.printStackTrace();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询