0
我正在使用Apache POI,並試圖發送xlsx
文件作爲HTTP請求並將其作爲響應返回。我正在使用jayway restassured
進行HTTP請求。使用Apache POI將byteArray轉換爲XSSFWorkbook
這裏是我發送請求
File file = new File("path");
String response = given().multipart(file).when().post("URL").getBody().asString();
byte[] bytes = response.getBytes("ISO-8859-1");
InputStream stream = new ByteArrayOutputStream(bytes);
try
{
XSSFWorkbook workbook = new XSSFWorkbook(stream);
}
catch(Exception e){
e.printStackTrace();
}
這裏是爲請求生成響應
XSSFWorkbook workBook; //this workBook has the workbook sent as HTTP request
//code to make changes in workBook
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
workBook.write(outStream);
byte[] byteArray = outStream.toByteArray();
String responseBody = new String(byteArray, "ISO-8859-1");
context.response().putHeader("Content-Type", "multipart/form-data").setStatusCode(200).end(responseBody);
因此,代碼的代碼的一部分,我試圖做的發送一個xlsx
文件作爲請求進行一些更改並將其作爲字符串響應返回,將其轉換回xssfworkbook。當轉換後,我在下面的線 -
XSSFWorkbook workbook = new XSSFWorkbook(stream);
的錯誤,我得到得到錯誤是
java.util.zip.ZipException: invalid code lengths set