|
@@ -1,5 +1,8 @@
|
|
|
package org.springblade.manager.utils;
|
|
|
|
|
|
+import com.aspose.cells.Column;
|
|
|
+import com.aspose.cells.ColumnCollection;
|
|
|
+import com.aspose.cells.SaveFormat;
|
|
|
import com.spire.xls.CellRange;
|
|
|
import com.spire.xls.FileFormat;
|
|
|
import com.spire.xls.Workbook;
|
|
@@ -18,9 +21,8 @@ import org.springblade.core.tool.utils.IoUtil;
|
|
|
import org.springblade.core.tool.utils.ResourceUtil;
|
|
|
import org.springblade.manager.vo.DateFormat;
|
|
|
|
|
|
-import java.io.File;
|
|
|
-import java.io.FileInputStream;
|
|
|
-import java.io.InputStream;
|
|
|
+import java.awt.*;
|
|
|
+import java.io.*;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
@@ -37,7 +39,7 @@ public class ExcelInfoUtils {
|
|
|
|
|
|
// 解析原始excel
|
|
|
Workbook wb = new Workbook();
|
|
|
- wb.loadFromMHtml(inputStream);
|
|
|
+ wb.loadFromMHtml(getInputStreamByUrl(inputStream));
|
|
|
Worksheet sheet = wb.getWorksheets().get(0);
|
|
|
HTMLOptions options = new HTMLOptions();
|
|
|
options.setImageEmbedded(true);
|
|
@@ -207,6 +209,34 @@ public class ExcelInfoUtils {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 解析excel 对隐藏的列设置初始列宽
|
|
|
+ * @param inputStream
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ public static InputStream getInputStreamByUrl(InputStream inputStream) throws Exception {
|
|
|
+ com.aspose.cells.Workbook workbook = new com.aspose.cells.Workbook(inputStream);
|
|
|
+ com.aspose.cells.Worksheet worksheet = workbook.getWorksheets().get(0);
|
|
|
+ // 获取工作表中所有列
|
|
|
+ ColumnCollection columns = worksheet.getCells().getColumns();
|
|
|
+ // 遍历所有列
|
|
|
+ for (int i = 0; i < columns.getCount(); i++) {
|
|
|
+ Column column = columns.get(i);
|
|
|
+ // 如果列是隐藏的(列宽为0)
|
|
|
+ if (column.isHidden()) {
|
|
|
+ // 解除隐藏并设置一个最小列宽(例如0.1)
|
|
|
+ column.setHidden(false);
|
|
|
+ column.setWidth(0.1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 将工作簿保存到ByteArrayOutputStream,然后转换为ByteArrayInputStream
|
|
|
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
|
+ workbook.save(outputStream, SaveFormat.XLSX);
|
|
|
+ return new ByteArrayInputStream(outputStream.toByteArray());
|
|
|
+ }
|
|
|
/**
|
|
|
* 在线编辑excel 操作
|
|
|
*
|