main
黄海 2 years ago
parent 8df6f6c35d
commit b4c317778a

@ -1,12 +1,5 @@
package UnitTest.ImportExcel;
import com.aspose.cells.*;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Color;
import org.apache.poi.ss.usermodel.Comment;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddressList;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
@ -14,7 +7,6 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
public class TestTitle {
@ -121,60 +113,6 @@ public class TestTitle {
return style;
}
/**
* EXCEL
*
* @param source
*/
public static void getSummary(String source, String target) throws Exception {
//使用AsposeCells增加两列
boolean auth = authrolizeLicense();
if (!auth) {
System.out.println("aspose 许可无效!");
return;
}
com.aspose.cells.Workbook wb = new com.aspose.cells.Workbook(source);
Worksheet sheet = wb.getWorksheets().get(0);
//添加列
Cells cells = sheet.getCells();
cells.insertColumns(0, 2);//在第一列前增加两列,一列是序号,另一列是单位名称
// 合并单元格:第三行、第四行的第一列
sheet.getCells().merge(2, 0, 2, 1);
// 设置背景色为黄色
Style style = wb.createStyle();
style.setForegroundColor(com.aspose.cells.Color.getYellow());
style.setPattern(BackgroundType.SOLID);
// 获取合并后的单元格
com.aspose.cells.Row row = sheet.getCells().getRow(2);
com.aspose.cells.Cell cell = row.getFirstCell();
//应用样式
cell.setStyle(style);
//保存
wb.save(target);
}
/**
* AsposeCells
*
* @return
*/
public static boolean authrolizeLicense() {
boolean result = false;
try {
InputStream is = com.aspose.cells.License.class.getResourceAsStream("/com.aspose.cells.lic_2999.xml");
License asposeLicense = new License();
asposeLicense.setLicense(is);
is.close();
result = true;
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
public static void main(String[] args) throws Exception {
//学校上传的Excel
String filePath = path + "1.xlsx";
@ -202,7 +140,5 @@ public class TestTitle {
} catch (IOException e) {
e.printStackTrace();
}
//生成汇总文件,并增加一列,一般是单位名称
getSummary(filePath, filePath2);
}
}

Loading…
Cancel
Save