💄 调整应收账单汇总表行边框样式
This commit is contained in:
+29
-3
@@ -26,6 +26,7 @@ import com.bms.receivable.domain.ArBillDetail;
|
||||
import com.bms.receivable.domain.ArBillDetailFee;
|
||||
import com.bms.receivable.domain.ArExportTemplate;
|
||||
import org.apache.poi.ss.SpreadsheetVersion;
|
||||
import org.apache.poi.ss.usermodel.BorderStyle;
|
||||
import org.apache.poi.ss.usermodel.FillPatternType;
|
||||
import org.apache.poi.ss.usermodel.IndexedColors;
|
||||
import org.apache.poi.xssf.usermodel.XSSFCell;
|
||||
@@ -58,6 +59,7 @@ public class SummaryArBillWorkbookWriter extends ArBillWorkbookSupport {
|
||||
String receiveTimePeriod = exportReceiveTimeRange(
|
||||
detailMapper.selectReceiveTimeRangeByBillId(bill.getArBillId()), "yyyyMMdd", "-");
|
||||
prepareTemplate(workbook, bill, receiveTimePeriod);
|
||||
SummaryStyles summaryStyles = createSummaryStyles(workbook);
|
||||
DetailStyles detailStyles = createDetailStyles(workbook);
|
||||
byte[] skeleton = serialize(workbook);
|
||||
String summaryPath = partPath(workbook.getSheetAt(0));
|
||||
@@ -94,7 +96,7 @@ public class SummaryArBillWorkbookWriter extends ArBillWorkbookSupport {
|
||||
for (ZipEntry entry; (entry = zip.getNextEntry()) != null; ) {
|
||||
output.putNextEntry(new ZipEntry(entry.getName()));
|
||||
if (summaryPath.equals(entry.getName())) {
|
||||
writeSummary(summary, bill, groups, result.amount(), receiveTimePeriod, output);
|
||||
writeSummary(summary, bill, groups, result.amount(), receiveTimePeriod, summaryStyles, output);
|
||||
} else if (detailPath.equals(entry.getName())) {
|
||||
Files.copy(detailXml, output);
|
||||
} else {
|
||||
@@ -195,6 +197,27 @@ public class SummaryArBillWorkbookWriter extends ArBillWorkbookSupport {
|
||||
return new DetailStyles(normal, failed, workbook.getSheetAt(1).getRow(4).getHeightInPoints());
|
||||
}
|
||||
|
||||
/** 产品行之间不画网格线;最后一行沿用模板底边,组成完整外框。 */
|
||||
private SummaryStyles createSummaryStyles(XSSFWorkbook workbook) throws IOException {
|
||||
XSSFRow source = requireRow(workbook.getSheetAt(0), SUMMARY_START_ROW - 1);
|
||||
int[] normal = new int[7];
|
||||
int[] last = new int[7];
|
||||
for (int column = 0; column < normal.length; column++) {
|
||||
XSSFCellStyle original = source.getCell(column, XSSFRow.MissingCellPolicy.CREATE_NULL_AS_BLANK).getCellStyle();
|
||||
XSSFCellStyle lastStyle = workbook.createCellStyle();
|
||||
lastStyle.cloneStyleFrom(original);
|
||||
lastStyle.setBorderTop(BorderStyle.NONE);
|
||||
if (column > 0) lastStyle.setBorderLeft(BorderStyle.NONE);
|
||||
if (column < normal.length - 1) lastStyle.setBorderRight(BorderStyle.NONE);
|
||||
last[column] = Short.toUnsignedInt(lastStyle.getIndex());
|
||||
XSSFCellStyle normalStyle = workbook.createCellStyle();
|
||||
normalStyle.cloneStyleFrom(lastStyle);
|
||||
normalStyle.setBorderBottom(BorderStyle.NONE);
|
||||
normal[column] = Short.toUnsignedInt(normalStyle.getIndex());
|
||||
}
|
||||
return new SummaryStyles(normal, last);
|
||||
}
|
||||
|
||||
private DetailResult writeDetails(SheetXml sheet, ArBill bill, OutputStream output,
|
||||
Map<String, ProductSummary> groups, DetailStyles styles) throws IOException {
|
||||
writeUtf8(output, sheet.prefix());
|
||||
@@ -307,17 +330,19 @@ public class SummaryArBillWorkbookWriter extends ArBillWorkbookSupport {
|
||||
}
|
||||
|
||||
private void writeSummary(SheetXml sheet, ArBill bill, Map<String, ProductSummary> groups,
|
||||
BigDecimal total, String receiveTimePeriod, OutputStream output) throws IOException {
|
||||
BigDecimal total, String receiveTimePeriod, SummaryStyles styles,
|
||||
OutputStream output) throws IOException {
|
||||
writeUtf8(output, sheet.prefix());
|
||||
for (int row = 1; row <= 3; row++) writeUtf8(output, sheet.rows().get(row));
|
||||
int rowNumber = SUMMARY_START_ROW;
|
||||
for (ProductSummary product : groups.values()) {
|
||||
String row = shiftRowXml(sheet.rows().get(4), rowNumber);
|
||||
int[] rowStyles = rowNumber == SUMMARY_START_ROW + groups.size() - 1 ? styles.last() : styles.normal();
|
||||
Object[] values = {rowNumber - 3, bill.getCustomerName(), product.name, receiveTimePeriod,
|
||||
product.amount, bill.getCurrency(), SUMMARY_REMARK};
|
||||
for (int index = 0; index < values.length; index++) {
|
||||
row = replaceCellXml(row, (char) ('A' + index) + String.valueOf(rowNumber),
|
||||
values[index], values[index] instanceof Number);
|
||||
values[index], values[index] instanceof Number, rowStyles[index]);
|
||||
}
|
||||
writeUtf8(output, row);
|
||||
rowNumber++;
|
||||
@@ -386,6 +411,7 @@ public class SummaryArBillWorkbookWriter extends ArBillWorkbookSupport {
|
||||
|
||||
private record SheetXml(String prefix, Map<Integer, String> rows, String suffix) { }
|
||||
private record DetailResult(int count, int lastRow, BigDecimal amount) { }
|
||||
private record SummaryStyles(int[] normal, int[] last) { }
|
||||
private record DetailStyles(int[] normal, int[] failed, float rowHeight) { }
|
||||
private record DetailAmounts(BigDecimal freight, BigDecimal processing, BigDecimal remote,
|
||||
BigDecimal surcharge, BigDecimal romania, BigDecimal total) { }
|
||||
|
||||
Reference in New Issue
Block a user