TA的每日心情 | 慵懒 2016-4-26 12:45 |
---|
签到天数: 3 天 连续签到: 2 天 [LV.2]测试排长
|
我自己写了一个java程序,程序如下,通过eclipse调用方法是正确的(备注:这个java程序中引入了第三方的poi的jar包)
- package com.luqiao.test;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.List;
- import javax.swing.JOptionPane;
- //下面是和数据导出有关的包
- import org.apache.poi.xssf.usermodel.XSSFCell;
- import org.apache.poi.xssf.usermodel.XSSFCellStyle;
- import org.apache.poi.xssf.usermodel.XSSFRow;
- import org.apache.poi.xssf.usermodel.XSSFSheet;
- import org.apache.poi.xssf.usermodel.XSSFWorkbook;
- public class ExportExcel {
- private static String filepath = "E://aa.xlsx";
- public static XSSFCell cell;
- public static XSSFRow row;
- public static FileInputStream ExcelFile;
- public static XSSFSheet sheet;
- public static XSSFWorkbook wb;
- public static void Export(int rowNo, int colNo, String result, boolean isHeader, List<String> header) throws Exception {
-
- ExcelFile=new FileInputStream(filepath);
-
- wb = new XSSFWorkbook(ExcelFile);
- sheet = wb.getSheet("aa");
- sheet.setDefaultColumnWidth(15);
-
- if (isHeader) {
-
- if(sheet.getRow(rowNo)==null){
- row=sheet.createRow(0);
-
- }
-
- else {
- row=sheet.getRow(0);
- }
- for (int i = 0; i < header.size(); i++) {
- XSSFCell cell = row.getCell(i);
- cell.setCellValue(header.get(i));
-
-
- }
- }
-
- if(sheet.getRow(rowNo)==null){
- row=sheet.createRow(rowNo);
-
- }
-
- else {
- row=sheet.getRow(rowNo);
- }
-
- //如果单元格是空,就返回null
- cell=row.getCell(colNo,row.RETURN_BLANK_AS_NULL);
- if(cell==null){
- cell=row.createCell(colNo);
- cell.setCellValue(result);
-
- }
- else {cell.setCellValue(result);}
- try {
- // 默认导出到E盘下
- FileOutputStream os=new FileOutputStream(filepath);
- wb.write(os);
- os.flush();
- os.close();
-
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- public static String getCellData(int rowNo,int colNo) throws Exception {
-
- row=sheet.getRow(rowNo);
- cell=row.getCell(colNo);
- String cellData=cell.getCellType()==XSSFCell.CELL_TYPE_STRING?cell.getStringCellValue():
- String.valueOf(Math.round(cell.getNumericCellValue()));
- return cellData;
- }
- public static void main (String []args) throws Exception{
- boolean flag=false;
- String tel="13205920075";
- for(int i=0;i<50;i++){
- //System.out.println(tel);
- List<String> list=new ArrayList<String>();
-
- Export(i, 0, tel, flag, list);
- Export(i, 1, "123456", flag, list);
- //System.out.println(exportdata.getCellData(i, 0)+""+exportdata.getCellData(i, 1) );
- }
-
- }
- }
复制代码 把上面的程序打包成jar包后,放到jmeter的bin/lib/ext目录下,然后调用方法getCellData的时候就会报错,报错信息如下:org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval Sourced file: inline evaluation of: ``import com.luqiao.test.*; import java.io.FileInputStream; import java.io.FileNot . . . '' : Method Invocation data1.getCellData
只要我写的java程序引入第三方的jar包,jmeter调用的时候都报如上的错误,找不到什么原因。求大神们指导?
|
|