Ejemplo n.º 1
0
            public void CreateHeaderRow()
            {
                NPOI.SS.UserModel.Sheet sheet = _currentSheet;
                Row row = sheet.CreateRow(sheet.PhysicalNumberOfRows);

                row.Height = ((short)400);
                for (int i = 0; i < 6; i++)
                {
                    row.CreateCell(i).CellStyle = (_style_4);
                    if (i == 2 || i == 3 || i == 4)
                    {
                        sheet.SetColumnWidth(i, 3500);
                    }
                    else if (i == 5)
                    {
                        sheet.SetColumnWidth(i, 10000);
                    }
                    else
                    {
                        sheet.SetColumnWidth(i, 8000);
                    }
                }
                Cell cell = row.GetCell(0);

                SetCellValue(cell, "Data validation cells");
                cell = row.GetCell(1);
                SetCellValue(cell, "Condition");
                cell = row.GetCell(2);
                SetCellValue(cell, "Allow blank");
                cell = row.GetCell(3);
                SetCellValue(cell, "Prompt box");
                cell = row.GetCell(4);
                SetCellValue(cell, "Error box");
                cell = row.GetCell(5);
                SetCellValue(cell, "Other settings");
            }
Ejemplo n.º 2
0
 /// <summary>
 /// Sets the width of the column.
 /// </summary>
 /// <param name="column">The column.</param>
 /// <param name="width">The width.</param>
 public void SetColumnWidth(int column, int width)
 {
     _sheet.SetColumnWidth(column, width);
 }
Ejemplo n.º 3
0
        public void TestColumnWidth()
        {
            //Check we can correctly read column widths from a reference workbook
            HSSFWorkbook wb = OpenSample("colwidth.xls");

            //reference values
            int[] ref1 = { 365, 548, 731, 914, 1097, 1280, 1462, 1645, 1828, 2011, 2194, 2377, 2560, 2742, 2925, 3108, 3291, 3474, 3657 };

            NPOI.SS.UserModel.Sheet sh = wb.GetSheetAt(0);
            for (char i = 'A'; i <= 'S'; i++)
            {
                int idx = i - 'A';
                int w   = sh.GetColumnWidth(idx);
                Assert.AreEqual(ref1[idx], w);
            }

            //the second sheet doesn't have overridden column widths
            sh = wb.GetSheetAt(1);
            int def_width = sh.DefaultColumnWidth;

            for (char i = 'A'; i <= 'S'; i++)
            {
                int idx = i - 'A';
                int w   = sh.GetColumnWidth(idx);
                //getDefaultColumnWidth returns width measured in characters
                //getColumnWidth returns width measured in 1/256th units
                Assert.AreEqual(def_width * 256, w);
            }

            //Test new workbook
            wb = new HSSFWorkbook();
            sh = wb.CreateSheet();
            sh.DefaultColumnWidth = (10);
            Assert.AreEqual(10, sh.DefaultColumnWidth);
            Assert.AreEqual(256 * 10, sh.GetColumnWidth(0));
            Assert.AreEqual(256 * 10, sh.GetColumnWidth(1));
            Assert.AreEqual(256 * 10, sh.GetColumnWidth(2));
            for (char i = 'D'; i <= 'F'; i++)
            {
                short w = (256 * 12);
                sh.SetColumnWidth(i, w);
                Assert.AreEqual(w, sh.GetColumnWidth(i));
            }

            //serialize and read again
            wb = HSSFTestDataSamples.WriteOutAndReadBack(wb);

            sh = wb.GetSheetAt(0);
            Assert.AreEqual(10, sh.DefaultColumnWidth);
            //columns A-C have default width
            Assert.AreEqual(256 * 10, sh.GetColumnWidth(0));
            Assert.AreEqual(256 * 10, sh.GetColumnWidth(1));
            Assert.AreEqual(256 * 10, sh.GetColumnWidth(2));
            //columns D-F have custom width
            for (char i = 'D'; i <= 'F'; i++)
            {
                short w = (256 * 12);
                Assert.AreEqual(w, sh.GetColumnWidth(i));
            }

            // Check for 16-bit signed/unsigned error:
            sh.SetColumnWidth(0, 40000);
            Assert.AreEqual(40000, sh.GetColumnWidth(0));
        }