2016-08-20 7 views
-3

일부 my.xls 파일에서 requestPayLoad Json 객체를 읽고 싶습니다. 응답을 다시 작성하고 싶습니다. 어떻게해야합니까?Gatling : - scala excel 파일에서 JSON 객체를 읽으십시오.

저는 스칼라에 매우 익숙합니다. 코드 스핀이 도움이 될 것입니다.

나는이 라이브러리를 말하는 겁니다하지만

https://github.com/folone/poi.scala

을 작동하지 않습니다 나는 아래와 같은 자바 코드를 작성하지만,

public class ExcelUtils { 

    private static Sheet excelWorkSheet; 
    private static Workbook excelWorkBook; 
    private static Cell cell; 

    public static void setExcelFile(String path, String sheetName) throws Exception { 
     InputStream excelFileInputStream = new FileInputStream(path); 

     String fileExtensionName = path.substring(path.indexOf(".")); 

     if (fileExtensionName.equals(".xlsx")) { 
      excelWorkBook = new XSSFWorkbook(excelFileInputStream); 
     } else if(fileExtensionName.equals(".xls")) { 
      excelWorkBook = new HSSFWorkbook(excelFileInputStream); 
     } 

     excelWorkSheet = excelWorkBook.getSheet(sheetName); 
    } 

    public static String getCellData(int rowNum, int colNum) throws Exception { 
     cell = excelWorkSheet.getRow(rowNum).getCell(colNum); 
     String cellData = cell.getStringCellValue(); 
     return cellData; 
    } 

    public static Sheet getExcelWorkSheet() throws IOException { 
     return excelWorkSheet; 
    } 
} 

답변

-1

마지막으로 나는 '스칼라에서 동일한 코드를 시뮬레이션 할 수 없습니다 나는 그것을 분류 할 수있다. build.gradle 파일

dependencies { 
// compile ('commons-collections:commons-collections:3.2') 
    compile ('org.scala-lang:scala-library:2.11.8') 
    compile ('org.scala-lang:scala-compiler:2.11.8') 
    compile group: 'org.apache.poi', name: 'poi', version: '3.9' 
    compile group: 'org.apache.poi', name: 'poi-ooxml', version: '3.9' 
} 

그리고 스칼라 코드에서 추가 Gradle을 종속성

package mypackage 

import java.io.FileInputStream 

import org.apache.poi.hssf.usermodel.HSSFWorkbook 
import org.apache.poi.ss.usermodel.Cell 
import org.apache.poi.ss.usermodel.Sheet 
import org.apache.poi.xssf.usermodel.XSSFWorkbook 

class ExcelUtils { 

// private var cellData: String = null; 

    def getCellData(path: String, sheetName: String, rowNum: Int, colNum: Int): String = { 
    val excelFileInputStream = new FileInputStream(path); 

    val fileExtensionName = path.substring(path.indexOf(".")); 
    var cellData: String = null; 

    if (fileExtensionName.equals(".xlsx")) { 
     val excelWorkBookXlxs = new XSSFWorkbook(excelFileInputStream); 
     val excelWorkSheetXlxs = excelWorkBookXlxs.getSheet(sheetName); 
     val cell = excelWorkSheetXlxs.getRow(rowNum).getCell(colNum); 
     cellData = cell.getStringCellValue(); 
    } else if (fileExtensionName.equals(".xls")) { 
     val excelWorkBookXls = new HSSFWorkbook(excelFileInputStream); 
     val excelWorkSheetXls = excelWorkBookXls.getSheet(sheetName); 
     val cell = excelWorkSheetXls.getRow(rowNum).getCell(colNum); 
     cellData = cell.getStringCellValue(); 
    } 
    return cellData; 
    } 
} 
입니다