|
@@ -5,16 +5,8 @@ import java.io.*;
|
|
|
import java.lang.reflect.Constructor;
|
|
|
import java.lang.reflect.Field;
|
|
|
import java.math.BigDecimal;
|
|
|
-import java.net.HttpURLConnection;
|
|
|
-import java.net.URL;
|
|
|
-import java.net.URLEncoder;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.Comparator;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.net.*;
|
|
|
+import java.util.*;
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
import java.util.stream.Collectors;
|
|
|
import java.util.stream.Stream;
|
|
@@ -22,6 +14,7 @@ import java.util.stream.Stream;
|
|
|
import javax.imageio.ImageIO;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.galaxis.manatee.entity.chuanyun.dto.ExcelColumn;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
|
|
@@ -29,6 +22,21 @@ import org.apache.commons.lang.BooleanUtils;
|
|
|
import org.apache.commons.lang.CharUtils;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.apache.commons.lang.math.NumberUtils;
|
|
|
+import org.apache.http.*;
|
|
|
+import org.apache.http.client.ClientProtocolException;
|
|
|
+import org.apache.http.client.HttpClient;
|
|
|
+import org.apache.http.client.entity.UrlEncodedFormEntity;
|
|
|
+import org.apache.http.client.methods.CloseableHttpResponse;
|
|
|
+import org.apache.http.client.methods.HttpPost;
|
|
|
+import org.apache.http.client.methods.HttpUriRequest;
|
|
|
+import org.apache.http.client.utils.URIBuilder;
|
|
|
+import org.apache.http.client.utils.URIUtils;
|
|
|
+import org.apache.http.client.utils.URLEncodedUtils;
|
|
|
+import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
+import org.apache.http.impl.client.DefaultHttpClient;
|
|
|
+import org.apache.http.impl.client.HttpClients;
|
|
|
+import org.apache.http.message.BasicNameValuePair;
|
|
|
+import org.apache.http.util.EntityUtils;
|
|
|
import org.apache.poi.hssf.usermodel.*;
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
import org.apache.poi.ss.usermodel.Picture;
|
|
@@ -89,51 +97,30 @@ public class ExcelUtils {
|
|
|
row = sheet.createRow(i + 1);
|
|
|
for (int j = 0; j < values[i].length; j++) {
|
|
|
//生成图片
|
|
|
- if (j==2){
|
|
|
-// URL url = new URL(values[i][j]);
|
|
|
-// //打开链接
|
|
|
-// HttpURLConnection conn = (HttpURLConnection)url.openConnection();
|
|
|
-// //设置请求方式为"GET"
|
|
|
-// conn.setRequestMethod("GET");
|
|
|
-// //超时响应时间为5秒
|
|
|
-// conn.setConnectTimeout(5 * 1000);
|
|
|
-// //通过输入流获取图片数据
|
|
|
-// InputStream inStream = conn.getInputStream();
|
|
|
-// //得到图片的二进制数据,以二进制封装得到数据,具有通用性
|
|
|
-// byte[] data = readInputStream(inStream);
|
|
|
-// log.warn(data.toString());
|
|
|
-// //anchor主要用于设置图片的属性
|
|
|
-// HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 1023, 250,(short) 2, i, (short) 3, i+1);
|
|
|
-// //Sets the anchor type (图片在单元格的位置)
|
|
|
-// //0 = Move and size with Cells, 2 = Move but don't size with cells, 3 = Don't move or size with cells.
|
|
|
-// anchor.setAnchorType(0);
|
|
|
-// HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
|
|
|
-// patriarch.createPicture(anchor, wb.addPicture(data, HSSFWorkbook.PICTURE_TYPE_PNG));
|
|
|
-// Sheet first=wb.createSheet("first");
|
|
|
+ if (j==3){
|
|
|
+
|
|
|
Drawing drawing=sheet.createDrawingPatriarch();
|
|
|
|
|
|
CreationHelper creationHelper=wb.getCreationHelper();
|
|
|
|
|
|
ClientAnchor clientAnchor=creationHelper.createClientAnchor();
|
|
|
- clientAnchor.setCol1(2);
|
|
|
+ clientAnchor.setCol1(3);
|
|
|
clientAnchor.setRow1(i);
|
|
|
- //获取图片
|
|
|
- BufferedInputStream in = new BufferedInputStream(new URL("https://lmichelin.fr/content/images/size/w2000/2019/05/5c1bb7dd5e7cc9678fcdc39f_Hello-World-Header.png").openStream());
|
|
|
- BufferedImage bufferedImage= ImageIO.read(in);
|
|
|
-
|
|
|
-
|
|
|
- InputStream inputStream=new BufferedInputStream(new URL("https://lmichelin.fr/content/images/size/w2000/2019/05/5c1bb7dd5e7cc9678fcdc39f_Hello-World-Header.png").openStream());
|
|
|
+// //获取图片
|
|
|
+// BufferedInputStream in = new BufferedInputStream(new URL("https://lmichelin.fr/content/images/size/w2000/2019/05/5c1bb7dd5e7cc9678fcdc39f_Hello-World-Header.png").openStream());
|
|
|
+// BufferedImage bufferedImage= ImageIO.read(in);
|
|
|
+// sendRequest(values[i][j]);
|
|
|
+ InputStream inputStream=new FileInputStream("save.jpg");
|
|
|
byte[] bytes= IOUtils.toByteArray(inputStream);
|
|
|
int helloWorldIndex=wb.addPicture(bytes,Workbook.PICTURE_TYPE_PNG);
|
|
|
inputStream.close();
|
|
|
|
|
|
//获取图片尺寸,用于修改单元格大小
|
|
|
-// int width=bufferedImage.getWidth();
|
|
|
- int height=bufferedImage.getHeight();
|
|
|
+// int height=bufferedImage.getHeight();
|
|
|
inputStream.close();
|
|
|
Picture picture = drawing.createPicture(clientAnchor,helloWorldIndex);
|
|
|
picture.resize();
|
|
|
- row.setHeight((short)(height*15));
|
|
|
+// row.setHeight((short)(height*15));
|
|
|
}else{
|
|
|
//将内容按顺序赋给对应的列对象
|
|
|
row.createCell(j).setCellValue(values[i][j]);
|
|
@@ -143,6 +130,31 @@ public class ExcelUtils {
|
|
|
return wb;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ public static void sendRequest() throws URISyntaxException, IOException {
|
|
|
+ HttpClient httpClient = new DefaultHttpClient();
|
|
|
+
|
|
|
+ String url = "https://www.h3yun.com/Api/DownloadBizObjectFile";
|
|
|
+
|
|
|
+ URIBuilder uriBuilder = new URIBuilder(url);
|
|
|
+ List<NameValuePair> list = new LinkedList<>();
|
|
|
+ BasicNameValuePair param1 = new BasicNameValuePair("attachmentId", "fc6abff0-4914-4eda-a0fa-c481094f0d79");
|
|
|
+ BasicNameValuePair param2 = new BasicNameValuePair("EngineCode", "qgvjpgbs50powyd6xyzxzakg3");
|
|
|
+ list.add(param1);
|
|
|
+ list.add(param2);
|
|
|
+ uriBuilder.setParameters(list);
|
|
|
+ HttpUriRequest request = new HttpPost(uriBuilder.build());
|
|
|
+ request.setHeader("EngineCode","qgvjpgbs50powyd6xyzxzakg3");
|
|
|
+ request.setHeader("EngineSecret","BsuPomgoblb0gDdrCBmzkq5KcWlz+2OXgetN1gFgnZgXmdgHdDpGgA==");
|
|
|
+ HttpResponse response = httpClient.execute(request);
|
|
|
+ InputStream stream = response.getEntity().getContent();
|
|
|
+ BufferedImage bufferedImage= ImageIO.read(stream);
|
|
|
+ File outputfile = new File("save.jpg");
|
|
|
+ ImageIO.write(bufferedImage,"jpeg",outputfile);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 导入Excel
|
|
|
* @param path
|