Document Solutions for Excel, Java Edition | Document Solutions
Features / Print Settings / Configure Columns to Repeat at Left and Right
In This Topic
    Configure Columns to Repeat at Left and Right
    In This Topic

    You can configure columns in a worksheet to repeat them at the left by using the setPrintTitleColumns method and at the right by using the setPrintTailColumns method of the IPageSetup interface.

    This feature is useful especially when you're using DsExcel Java to create reports wherein you want to repeat specific title columns and tail columns in the exported file. With support for repeating specific columns at the left and right side of the page; it becomes much easier and quicker to handle and visualize spreadsheets containing large number of columns.

    While exporting a spreadsheet with repeating columns to a PDF file, the tail columns will be exported only when its index is larger than the page's last column's index. Otherwise, the tail column is ignored. For instance, if the Print Area is "A1:J200" and the right repeating column is "$I:$J"; it will print "$I:$J" repeatedly on each page. However, if users set the right repeating column to "$K:$L", then it will not print "$K:$L" (because the column index is larger than print area).

    Refer to the following example code in order to configure columns to repeat at the right.

    Java
    Copy Code
    // Initialize workbook
    Workbook workbook = new Workbook();
            
    // Fetch default worksheet
    IWorksheet worksheet = workbook.getWorksheets().get(0);
    
    // Populating cells in worksheet
    for (int i = 0; i < 200; i++)
        for (int j = 0; j < 8; j++) {
            worksheet.getRange(i, j).setValue(i);
            worksheet.getRange(i, 8).setValue("Row I");
            worksheet.getRange(i, 9).setValue("Row J");
        }
    
    // Repeat Columns from I to J at the right of each page while saving pdf
    worksheet.getPageSetup().setPrintTailColumns("$I:$J");
    
    // Saving workbook to pdf
    workbook.save("ConfigureTailColumns.pdf", SaveFileFormat.Pdf);

    Refer to the following example code in order to configure columns to repeat at the left.

    Java
    Copy Code
    // Set columns to repeat at left
    worksheet.getPageSetup().setPrintTitleColumns("$D:$G");