Example #1
0
        /**
         * Write out loads of labels, in order to test the shared string table
         */
        private void writeLabelsSheet(WritableSheet ws)
        {
            ws.getSettings().setProtected(true);
            ws.getSettings().setPassword("jxl");
            ws.getSettings().setVerticalFreeze(5);
            ws.getSettings().setDefaultRowHeight(25 * 20);

            WritableFont wf = new WritableFont(WritableFont.ARIAL, 12);
            wf.setItalic(true);

            WritableCellFormat wcf = new WritableCellFormat(wf);

            CellView cv = new CellView();
            cv.setSize(25 * 256);
            cv.setFormat(wcf);
            ws.setColumnView(0, cv);
            ws.setColumnView(1, 15);

            for (int i = 0; i < 61; i++)
                {
                Label l1 = new Label(0, i, "Common Label");
                Label l2 = new Label(1, i, "Distinct label number " + i);
                ws.addCell(l1);
                ws.addCell(l2);
                }

            // Frig this test record - it appears exactly on the boundary of an SST
            // continue record

            Label l3 = new Label(0, 61, "Common Label", wcf);
            Label l4 = new Label(1, 61, "1-1234567890", wcf);
            Label l5 = new Label(2, 61, "2-1234567890", wcf);
            ws.addCell(l3);
            ws.addCell(l4);
            ws.addCell(l5);

            for (int i = 62; i < 200; i++)
                {
                Label l1 = new Label(0, i, "Common Label");
                Label l2 = new Label(1, i, "Distinct label number " + i);
                ws.addCell(l1);
                ws.addCell(l2);
                }

            // Add in a last label which doesn't take the jxl.common.format
            wf = new WritableFont(WritableFont.TIMES, 10, WritableFont.BOLD);
            wf.setColour(Colour.RED);
            WritableCellFormat wcf2 = new WritableCellFormat(wf);
            wcf2.setWrap(true);
            Label l = new Label(0, 205, "Different format", wcf2);
            ws.addCell(l);

            // Add some labels to column 5 for autosizing
            Label l6 = new Label(5, 2, "A column for autosizing", wcf2);
            ws.addCell(l6);
            l6 = new Label(5, 4, "Another label, longer this time and " +
                           "in a different font");
            ws.addCell(l6);

            CellView cf = new CellView();
            cf.setAutosize(true);
            ws.setColumnView(5, cf);
        }