2016-08-20 1 views
-3

Je souhaite lire l'objet requestPayLoad Json de certains fichiers my.xls et je souhaite également y écrire une réponse. Comment puis-je y aller? Je suis très nouveau à scala, donc Code spinet aidera.Gatling: - scala Lire l'objet JSON à partir du fichier Excel

Je parle de cette bibliothèque, mais il ne fonctionne pas

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

J'écrit le code java comme ci-dessous, mais pas en mesure de simuler même code dans le 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; 
    } 
} 

Répondre

-1

Enfin je m capable de le trier. Ajout de dépendances Gradle dans un fichier 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' 
} 

et le code scala est

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; 
    } 
}