WritableWorkbook book = null;
WritableSheet sheet;
File file = null;
try {
WorkbookSettings workbookSettings = new WorkbookSettings();
workbookSettings.setGCDisabled(true);
file = new File(temPath + ".xls");
book = Workbook.createWorkbook(file, workbookSettings);
WritableCellFormat format = new WritableCellFormat();
format.setBackground(Colour.ORANGE);
format.setAlignment(Alignment.CENTRE);
sheet = book.createSheet("sheet1", 0);
sheet.getSettings().setDefaultColumnWidth(15);
if (dateFieldTitleList.size() > 3) {
sheet.setColumnView(0, 20);
sheet.setColumnView(1, 20);
} else {
sheet.setColumnView(0, 20);
}
for (int i = 0; i < dateFieldTitleList.size(); i++) {
Label lable = new Label(i, 0, dateFieldTitleList.get(i));
lable.setCellFormat(format);
sheet.addCell(lable);
}
for (int row = 0; row < detailDataList.size(); row++) {
for (int col = 0; col < detailFieldList.size(); col++) {
String value = "";
value = detailDataList.get(row).getValueAsString(detailFieldList.get(col));
Label lable = new Label(col, row + 1, value);
sheet.addCell(lable);
}
}
book.write();
} catch (Exception e) {
if (file != null) {
file.delete();
}
} finally {
if (book != null) {
try {
book.close();
} catch (Exception e) {
}
}
}
BufferedReader in = null;
HttpClient httpClient = null;
PostMethod postMethod = null;
StringBuffer inputLine = new StringBuffer();
try {
Protocol myhttps = new Protocol("https",
new MySSLProtocolSocketFactory(), 443);
Protocol.registerProtocol("https", myhttps);
httpClient = new HttpClient();
HttpConnectionManagerParams managerParams = httpClient
.getHttpConnectionManager().getParams();
managerParams.setConnectionTimeout(30000);
managerParams.setSoTimeout(30000);
postMethod = new PostMethod(url);
postMethod.getParams().setContentCharset("utf-8");
postMethod.setRequestHeader("Accept", "application/json");
CustomFilePart filePart = new CustomFilePart(fileName, file);
filePart.setCharSet("utf-8");
Part[] parts = { filePart };
postMethod.setRequestEntity(new MultipartRequestEntity(parts,
postMethod.getParams()));
int status = httpClient.executeMethod(postMethod);
if (status != HttpStatus.SC_OK) {
return null;
}
String str = "";
in = new BufferedReader(new InputStreamReader(
postMethod.getResponseBodyAsStream(), "UTF-8"));
while ((str = in.readLine()) != null) {
inputLine.append(str);
}
JSONObject result = JSON.parseObject(inputLine.toString());
return result;
} catch (Exception e) {
e.printStackTrace();
return null;
} finally {
try {
if (in != null) {
in.close();
}
if (postMethod != null) {
postMethod.releaseConnection();
}
} catch (IOException e) {
e.printStackTrace();
}
}
HttpPost httpPost = new HttpPost(url);
CloseableHttpResponse response = null;
CloseableHttpClient httpClient = HttpClientUtils.acceptsUntrustedCertsHttpClient();
RequestConfig requestConfig = RequestConfig.custom().
setSocketTimeout(4000).setConnectTimeout(4000).setConnectionRequestTimeout(4000).build();
httpPost.setConfig(requestConfig);
httpPost .addHeader("Content-Type", "application/json");
try {
StringEntity requestEntity = new StringEntity(JSON.toJSONString(data), "utf-8");
httpPost.setEntity(requestEntity);
response = httpClient.execute(httpPost, new BasicHttpContext());
if (response.getStatusLine().getStatusCode() != 200) {
throw new RuntimeException("请求出现错误,错误信息:" + response.getStatusLine().getStatusCode());
}
HttpEntity entity = response.getEntity();
if (entity != null) {
String resultStr = EntityUtils.toString(entity, "utf-8");
JSONObject result = JSON.parseObject(resultStr);
if (result.getInteger("errcode") == 0) {
result.remove("errcode");
result.remove("errmsg");
return result;
} else {
int errCode = result.getInteger("errcode");
String errMsg = result.getString("errmsg");
throw new OApiException(errCode, errMsg);
}
}
} catch (IOException e) {
e.printStackTrace();
}finally {
if (response != null) try {
response.close();
} catch (IOException e) {
e.printStackTrace();
}
if (httpClient != null) {
try {
httpClient.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return null;