提到post,其中Clough先生给出了答案,他已经编写了代码来获取这样的输出,
PLATINUM COMPUTERS(PVT) LTD NO 20/B, Main Street, Kandy, Sri Lanka. Land: 812254630 Mob: 712205220 Fax: 812254639 CUSTOMER INVOICE +-----------------------+----------------------+ |INFO |CUSTOMER | +-----------------------+----------------------+ |DATE: 2015-9-8 |ModernTec Distributors| |TIME: 10:53:AM |MOB: +94719530398 | |BILL NO: 12 |ADDRES: No 25, Main St| |INVOICE NO: 458-80-108 |reet, Kandy. | +-----------------------+----------------------+ | SELLING DETAILS | +-----------------+---------+-----+------------+ |ITEM | PRICE($)| QTY| VALUE| +-----------------+---------+-----+------------+ |Optical mouse | 120.00| 20| 2400.00| |Gaming keyboard | 550.00| 30| 16500.00| |320GB SATA HDD | 220.00| 32| 7040.00| |500GB SATA HDD | 274.00| 13| 3562.00| |1TB SATA HDD | 437.00| 11| 4807.00| |RE-DVD ROM | 144.00| 29| 4176.00| |DDR3 4GB RAM | 143.00| 13| 1859.00| |Blu-ray DVD | 94.00| 28| 2632.00| |WR-DVD | 122.00| 34| 4148.00| |Adapter | 543.00| 28| 15204.00| +-----------------+---------+-----+------------+ | RETURNING DETAILS | +-----------------+---------+-----+------------+ |ITEM | PRICE($)| QTY| VALUE| +-----------------+---------+-----+------------+ |320GB SATA HDD | 220.00| 4| 880.00| |WR-DVD | 122.00| 7| 854.00| |1TB SATA HDD | 437.00| 7| 3059.00| |RE-DVD ROM | 144.00| 4| 576.00| |Gaming keyboard | 550.00| 6| 3300.00| |DDR3 4GB RAM | 143.00| 7| 1001.00| +-----------------+---------+-----+------------+ GROSS 59,928.00 DISCOUNT(5%) 2,996.40 RETURN 9,670.00 PAYABLE 47,261.60 CASH 20,000.00 CHEQUE 15,000.00 CREDIT(BALANCE) 12,261.60 --------------------- --------------------- CASH COLLECTOR GOODS RECEIVED BY soulution by clough.com
上面输出的代码如下:
String company = "" + "PLATINUM COMPUTERS(PVT) LTD\n" + "NO 20/B, Main Street, Kandy, Sri Lanka.\n" + "Land: 812254630 Mob: 712205220 Fax: 812254639\n" + " \n" + "CUSTOMER INVOICE\n" + " \n"; List<String> t1Headers = Arrays.asList("INFO", "CUSTOMER"); List<List<String>> t1Rows = Arrays.asList( Arrays.asList("DATE: 2015-9-8", "ModernTec Distributors"), Arrays.asList("TIME: 10:53:AM", "MOB: +94719530398"), Arrays.asList("BILL NO: 12", "ADDRES: No 25, Main Street, Kandy."), Arrays.asList("INVOICE NO: 458-80-108", "") ); String t2Desc = "SELLING DETAILS"; List<String> t2Headers = Arrays.asList("ITEM", "PRICE($)", "QTY", "VALUE"); List<List<String>> t2Rows = Arrays.asList( Arrays.asList("Optical mouse", "120.00", "20", "2400.00"), Arrays.asList("Gaming keyboard", "550.00", "30", "16500.00"), Arrays.asList("320GB SATA HDD", "220.00", "32", "7040.00"), Arrays.asList("500GB SATA HDD", "274.00", "13", "3562.00"), Arrays.asList("1TB SATA HDD", "437.00", "11", "4807.00"), Arrays.asList("RE-DVD ROM", "144.00", "29", "4176.00"), Arrays.asList("DDR3 4GB RAM", "143.00", "13", "1859.00"), Arrays.asList("Blu-ray DVD", "94.00", "28", "2632.00"), Arrays.asList("WR-DVD", "122.00", "34", "4148.00"), Arrays.asList("Adapter", "543.00", "28", "15204.00") ); List<Integer> t2ColWidths = Arrays.asList(17, 9, 5, 12); String t3Desc = "RETURNING DETAILS"; List<String> t3Headers = Arrays.asList("ITEM", "PRICE($)", "QTY", "VALUE"); List<List<String>> t3Rows = Arrays.asList( Arrays.asList("320GB SATA HDD", "220.00", "4", "880.00"), Arrays.asList("WR-DVD", "122.00", "7", "854.00"), Arrays.asList("1TB SATA HDD", "437.00", "7", "3059.00"), Arrays.asList("RE-DVD ROM", "144.00", "4", "576.00"), Arrays.asList("Gaming keyboard", "550.00", "6", "3300.00"), Arrays.asList("DDR3 4GB RAM", "143.00", "7", "1001.00") ); String summary = "" + "GROSS\n" + "DISCOUNT(5%)\n" + "RETURN\n" + "PAYABLE\n" + "CASH\n" + "CHEQUE\n" + "CREDIT(BALANCE)\n"; String summaryVal = "" + "59,928.00\n" + "2,996.40\n" + "9,670.00\n" + "47,261.60\n" + "20,000.00\n" + "15,000.00\n" + "12,261.60\n"; String sign1 = "" + "---------------------\n" + "CASH COLLECTOR\n"; String sign2 = "" + "---------------------\n" + "GOODS RECEIVED BY\n"; String advertise = "soulution by clough.com"; //bookmark Board b = new Board(48); b.setInitialBlock(new Block(b, 46, 7, company).allowGrid(false).setBlockAlign(Block.BLOCK_CENTRE).setDataAlign(Block.DATA_CENTER)); b.appendTableTo(0, Board.APPEND_BELOW, new Table(b, 48, t1Headers, t1Rows)); b.getBlock(3).setBelowBlock(new Block(b, 46, 1, t2Desc).setDataAlign(Block.DATA_CENTER)); b.appendTableTo(5, Board.APPEND_BELOW, new Table(b, 48, t2Headers, t2Rows, t2ColWidths)); b.getBlock(10).setBelowBlock(new Block(b, 46, 1, t3Desc).setDataAlign(Block.DATA_CENTER)); b.appendTableTo(14, Board.APPEND_BELOW, new Table(b, 48, t3Headers, t3Rows, t2ColWidths)); Block summaryBlock = new Block(b, 35, 9, summary).allowGrid(false).setDataAlign(Block.DATA_MIDDLE_RIGHT); b.getBlock(19).setBelowBlock(summaryBlock); Block summaryValBlock = new Block(b, 12, 9, summaryVal).allowGrid(false).setDataAlign(Block.DATA_MIDDLE_RIGHT); summaryBlock.setRightBlock(summaryValBlock); Block sign1Block = new Block(b, 24, 7, sign1).setDataAlign(Block.DATA_BOTTOM_MIDDLE).allowGrid(false); summaryBlock.setBelowBlock(sign1Block); sign1Block.setRightBlock(new Block(b, 24, 7, sign2).setDataAlign(Block.DATA_BOTTOM_MIDDLE).allowGrid(false)); sign1Block.setBelowBlock(new Block(b, 48, 3, advertise).setDataAlign(Block.DATA_CENTER).allowGrid(false)); //b.showBlockIndex(true); System.out.println(b.invalidate().build().getPreview());
现在,我面临的问题是我不希望发票中有“退货明细”部分。我只想添加公司标题部分而不是信息和客户部分,然后仅出售详细信息和总计。
我正在编写自己根据自己的要求进行更改的代码,但无法剪切返回详细信息部分和“签名”部分。下面是我的代码:
String company = "" + "V.K Autos Larkana\n" + "Near Rehmaniya Masjid Larkana\n" + "Police Shopping Center Larkana\n" + "Cell: 0334-3269198, 0333-3910951\n" + " \n" + "CUSTOMER INVOICE\n" + " \n"; Calendar cal = Calendar.getInstance(); SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); List<String> t1Headers = Arrays.asList("INFO", "CUSTOMER"); List<List<String>> t1Rows = Arrays.asList( Arrays.asList("DATE: " + date + "", "" + txt_cnam.getText()), Arrays.asList("TIME: " + sdf.format(cal.getTime()) + "", "Bill No:" + billno + "") ); String t2Desc = "SELLING DETAILS"; List<String> t2Headers = Arrays.asList("ITEM", "QTY", "Rate", "Total"); List<List<String>> t2Rows = new ArrayList<List<String>>(); for (int i = 0; i < tbl_sale.getRowCount(); i++) { String pid = tbl_sale.getValueAt(i, 0).toString(); String item = tbl_sale.getValueAt(i, 1).toString(); String quant = tbl_sale.getValueAt(i, 2).toString(); String rate = tbl_sale.getValueAt(i, 3).toString(); String rs = tbl_sale.getValueAt(i, 4).toString(); ArrayList<String> temp = new ArrayList<String>(); temp.add(item); temp.add(quant); temp.add(rate); temp.add(rs); t2Rows.add(temp); } List<Integer> t2ColWidths = Arrays.asList(17, 9, 5, 12); String t3Desc = "Sub Total"; List<String> t3Headers = Arrays.asList("", "", "", ""); List<List<String>> t3Rows = Arrays.asList( Arrays.asList("WR-DVD", "122.00", "7", "854.00") ); String summary = "" + "Sub Total\n"; String summaryVal = "" + txt_total.getText() + "\n"; String sign1 = "" + "------------Thank You-------------\n"; String sign2 = "" + "-We value your visit-\n"; String advertise = "-We value your visit-"; try { Board b = new Board(48); b.setInitialBlock(new Block(b, 46, 7, company).allowGrid(false).setBlockAlign(Block.BLOCK_CENTRE).setDataAlign(Block.DATA_CENTER)); b.appendTableTo(0, Board.APPEND_BELOW, new Table(b, 48, t1Headers, t1Rows)); b.getBlock(3).setBelowBlock(new Block(b, 46, 1, t2Desc).setDataAlign(Block.DATA_CENTER)); b.appendTableTo(5, Board.APPEND_BELOW, new Table(b, 48, t2Headers, t2Rows, t2ColWidths)); b.getBlock(10).setBelowBlock(new Block(b, 46, 1, t3Desc).setDataAlign(Block.DATA_CENTER)); b.appendTableTo(14, Board.APPEND_BELOW, new Table(b, 48, t3Headers, t3Rows, t2ColWidths)); Block summaryBlock = new Block(b, 35, 3, summary).allowGrid(false).setDataAlign(Block.DATA_MIDDLE_RIGHT); b.getBlock(19).setBelowBlock(summaryBlock); Block summaryValBlock = new Block(b, 12, 3, summaryVal).allowGrid(false).setDataAlign(Block.DATA_MIDDLE_RIGHT); summaryBlock.setRightBlock(summaryValBlock); Block sign1Block = new Block(b, 24, 7, sign1).setDataAlign(Block.DATA_BOTTOM_MIDDLE).allowGrid(false); summaryBlock.setBelowBlock(sign1Block); sign1Block.setRightBlock(new Block(b, 24, 7, sign2).setDataAlign(Block.DATA_BOTTOM_MIDDLE).allowGrid(false)); sign1Block.setBelowBlock(new Block(b, 48, 3, advertise).setDataAlign(Block.DATA_CENTER).allowGrid(false)); System.out.println(b.invalidate().build().getPreview());
以上代码的输出为:
V.K Autos Larkana Near Rehmaniya Masjid Larkana Police Shopping Center Larkana Cell: 0334-3269198, 0333-3910951 CUSTOMER INVOICE +-----------------------+----------------------+ |INFO |CUSTOMER | +-----------------------+----------------------+ |DATE: 2016/01/27 |Mohammad Rafi Abro | |TIME: 23:23:49 |Bill No:9 | +-----------------------+----------------------+ | SELLING DETAILS | +-----------------+---------+-----+------------+ |ITEM | QTY| Rate| Total| +-----------------+---------+-----+------------+ |nuts | 50| 25| 1250| +-----------------+---------+-----+------------+ | Sub Total | +-----------------+---------+-----+------------+ | | | | | +-----------------+---------+-----+------------+ |WR-DVD | 122.00| 7| 854.00| +-----------------+---------+-----+------------+ Sub Total 1250 ------------Thank You-------- -We value your visit- -We value your visit-
但我想要这样的输出:
V.K Autos Larkana Near Rehmaniya Masjid Larkana Police Shopping Center Larkana Cell: 0334-3269198, 0333-3910951 CUSTOMER INVOICE +-----------------------+----------------------+ |INFO |CUSTOMER | +-----------------------+----------------------+ |DATE: 2016/01/27 |Mohammad Rafi Abro | |TIME: 23:23:49 |Bill No:9 | +-----------------------+----------------------+ | SELLING DETAILS | +-----------------+---------+-----+------------+ |ITEM | QTY| Rate| Total| +-----------------+---------+-----+------------+ |nuts | 50| 25| 1250| +-----------------+---------+-----+------------+ Sub Total 1250 ===== Thank you for your kind visit ===
而且我也想减小其宽度,当前板的宽度为48,但是当我将其值更改为40时,它也向我显示错误:(请任何人帮助我解决这个问题。
最终,我花了一整夜的时间编写代码:)好,感谢Clough先生提供的WAGU示例。
我的代码如下:
String company = "" + "V.K Autos Larkana\n" + "Near Rehmaniya Masjid Larkana\n" + "Police Shopping Center Larkana\n" + "Cell: 0334-3269198, 0333-3910951\n" + " \n" + "CUSTOMER INVOICE" + " "; Calendar cal = Calendar.getInstance(); SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); List<String> t1Headers = Arrays.asList("INFO", "CUSTOMER"); List<List<String>> t1Rows = Arrays.asList( Arrays.asList("DATE: " + date + "", "" + txt_cnam.getText()), Arrays.asList("TIME: " + sdf.format(cal.getTime()) + "", "Bill No:" + billno + "") ); String t2Desc = "SELLING DETAILS"; List<String> t2Headers = Arrays.asList("ITEM", "QTY", "Rate", "Total"); List<List<String>> t2Rows = new ArrayList<List<String>>(); for (int i = 0; i < tbl_sale.getRowCount(); i++) { String pid = tbl_sale.getValueAt(i, 0).toString(); String item = tbl_sale.getValueAt(i, 1).toString(); String quant = tbl_sale.getValueAt(i, 2).toString(); String rate = tbl_sale.getValueAt(i, 3).toString(); String rs = tbl_sale.getValueAt(i, 4).toString(); ArrayList<String> temp = new ArrayList<String>(); temp.add(item); temp.add(quant); temp.add(rate); temp.add(rs); t2Rows.add(temp); } List<Integer> t2ColWidths = Arrays.asList(16, 5, 7, 9); String t3Desc = "Sub Total"; List<String> t3Headers = Arrays.asList("", "", "", ""); List<List<String>> t3Rows = Arrays.asList( Arrays.asList("WR-DVD", "122.00", "7", "854.00") ); String summary = "" + "Sub Total\n"; String summaryVal = "" + txt_total.getText() + "\n"; String sign1 = "" +"------Thank you for your visit------\n"; String sign2 = "" + "-We value your visit-\n"; String advertise = "******** Soulution by AbroSoft *******\n* abrosoft@outlook.com # 03337584273 *"; try { Board b = new Board(48); b.setInitialBlock(new Block(b, 40, 6, company).allowGrid(true).setBlockAlign(Block.BLOCK_LEFT).setDataAlign(Block.DATA_CENTER)); b.appendTableTo(0, Board.APPEND_BELOW, new Table(b, 42, t1Headers, t1Rows)); b.getBlock(3).setBelowBlock(new Block(b, 40, 1, t2Desc).setDataAlign(Block.DATA_CENTER)); b.appendTableTo(5, Board.APPEND_BELOW, new Table(b, 40, t2Headers, t2Rows, t2ColWidths)); Block summaryBlock = new Block(b, 30, 1, summary).setDataAlign(Block.DATA_TOP_RIGHT); b.getBlock(10).setBelowBlock(summaryBlock); Block summaryValBlock = new Block(b, 9, 1, summaryVal).setDataAlign(Block.DATA_TOP_RIGHT); summaryBlock.setRightBlock(summaryValBlock); Block sign1Block = new Block(b, 40, 1, sign1).setDataAlign(Block.DATA_CENTER); b.getBlock(14).setBelowBlock(sign1Block); Block sign2Block = new Block(b, 40, 2, advertise).setDataAlign(Block.DATA_CENTER); b.getBlock(16).setBelowBlock(sign2Block); System.out.println(b.invalidate().build().getPreview());
现在的输出就像我需要的:)。输出如下:
+----------------------------------------+ | V.K Autos Larkana | | Near Rehmaniya Masjid Larkana | | Police Shopping Center Larkana | | Cell: 0334-3269198, 0333-3910951 | | | | CUSTOMER INVOICE | +--------------------+-------------------+ |INFO |CUSTOMER | +--------------------+-------------------+ |DATE: 2016/01/28 |Mohammad Rafi Abro | |TIME: 15:31:15 |Bill No:10 | +--------------------+-------------------+ | SELLING DETAILS | +----------------+-----+-------+---------+ |ITEM | QTY| Rate| Total| +----------------+-----+-------+---------+ |nuts | 12| 25| 300| |70 CC | 12| 7000| 84000| |125 CC | 13| 95000| 1235000| |12 | 25| 2500| 62500| +----------------+-----+-------+---------+ | Sub Total| 1381800| +------------------------------+---------+ | ------Thank you for your visit------ | +----------------------------------------+ | ******** Soulution by AbroSoft ******* | | * abrosoft@outlook.com # 03337584273 * | +----------------------------------------+
好吧,再次感谢