我爲我的iText表設置了一個標題,它有6列,後來我想爲另一個表使用相同的標題,並將colspans設置爲更通用,但是一行rowsn然後'再工作。奇怪的setRowspan錯誤/不能正常工作
這是我原來的(工作)的代碼與6列:
public static PdfPTable createHeaderContent() {
PdfPTable table = new PdfPTable(6);
table.setWidthPercentage(100);
PdfPCell dobicell = new PdfPCell();
dobicell.setColspan(2);
dobicell.addElement(new Phrase(docType, DOBIFONTADR));
dobicell.setBorder(Rectangle.LEFT | Rectangle.RIGHT | Rectangle.TOP);
table.addCell(dobicell);
dobicell = new PdfPCell();
dobicell.setColspan(2);
dobicell.addElement(new Phrase("Ing. Mario J. Schwaiger", DOBIFONTADR));
dobicell.setBorder(Rectangle.TOP);
table.addCell(dobicell);
dobicell = Dobilogo.getPiccell(92, 104);
dobicell.setBorder(Rectangle.TOP | Rectangle.RIGHT);
dobicell.setColspan(3);
dobicell.setRowspan(2);
table.addCell(dobicell);
dobicell = getKundenCol(kunde);
dobicell.setColspan(2);
dobicell.setBorder(Rectangle.LEFT | Rectangle.RIGHT | Rectangle.BOTTOM);
table.addCell(dobicell);
dobicell = getUserCell(user);
dobicell.setColspan(2);
table.addCell(dobicell);
table.setHeaderRows(1);
return table;
}
的「通用」的修改代碼幾乎相同:
public static PdfPTable createHeaderContent(int[] coldist) {
PdfPTable table = new PdfPTable(coldist[0] + coldist[1] + coldist[2]); //createHeaderContent(new int[]{4, 7, 4, 4, 7});
table.setWidthPercentage(100);
PdfPCell dobicell = new PdfPCell();
dobicell.setColspan(coldist[0]); //used to be 2, now 4
dobicell.addElement(new Phrase(doctype, DOBIFONTADR));
dobicell.setBorder(Rectangle.LEFT | Rectangle.RIGHT | Rectangle.TOP);
table.addCell(dobicell);
dobicell = new PdfPCell();
dobicell.setColspan(coldist[1]); //used to be 2, now 7
dobicell.addElement(new Phrase("Ing. Mario J. Schwaiger", DOBIFONTTITEL));
dobicell.setBorder(Rectangle.TOP);
table.addCell(dobicell);
dobicell = Dobilogo.getPiccell(92, 104);
dobicell.setBorder(Rectangle.TOP | Rectangle.RIGHT);
dobicell.setColspan(coldist[2]); //used to be 3, now 4
dobicell.setRowspan(2); // <--- This is fishy, but why?
table.addCell(dobicell);
dobicell = getKundenCol(kunde);
dobicell.setColspan(coldist[3]); //used to be 2, now 4
dobicell.setBorder(Rectangle.LEFT | Rectangle.RIGHT | Rectangle.BOTTOM);
table.addCell(dobicell);
dobicell = getUserCell(user);
dobicell.setColspan(coldist[4]); //used to be 2, now 7
table.addCell(dobicell);
table.setHeaderRows(1);
return table;
}
起初我假設有另一行隱藏和使用dobicell.setRowspan(3);
但這改變了第一個數據行已經。嘗試添加另一個單元格將其放在標題後的第一行。
奇怪的是,當我把最後一部分中的用戶單元擴大到整個行分隔的單元格消失。
是否有解決方案或此問題的原因?
你*。*「與6列原來的(工作)的代碼」看起來奇怪,因爲嚴格來說,需要7列:你有兩次'setColspan(2)'一次'setColspan( 3)',所以總結出你有7欄。此外,你有'setHeaderRows(1)' - 你如何期望在單個標題行中與'setRowspan(2)'結合使用?你已經刪除了你的*「修改代碼」*中的第一個問題,但保留了第二個問題。看起來好像兩個問題偶然相遇都會相互抵消,但第二個問題就會導致你的觀察。 – mkl
我剛剛檢查了整個代碼,它很奇怪:是的,你說得對,我在那裏有一個'setColspan(3)'。但是把它放回'setColspan(2)'不起作用。當我寫這個問題時,我做了一些測試,可能會漏掉並留下。與'setHeaderRows(1)'相關的 - 你也注意到了。不,這是原始代碼。當我在編程時,我首先從可用的在線資源中複製了一些工作代碼,然後忘記調整它,因爲它工作正常。 'setHeaderRows(2)'什麼都沒做。顯然是由於rowspan,但這只是一個猜測。 – Qohelet
你說得對。在修改後的版本中,我仍然有'setHeaderRows(1)'。用'setHeaderRows(2)替換'解決了問題 – Qohelet