コード例 #1
0
ファイル: ColumnHelper.cs プロジェクト: founshi/npoi
        //YK: GetXYZArray() array accessors are deprecated in xmlbeans with JDK 1.5 support
        public static void SortColumns(CT_Cols newCols)
        {
            List <CT_Col> colArray = newCols.GetColList();

            colArray.Sort(new CTColComparator());
            newCols.SetColArray(colArray);
        }
コード例 #2
0
ファイル: ColumnHelper.cs プロジェクト: founshi/npoi
        /**
         * Returns the Column at the given 1 based index.
         * POI default is 0 based, but the file stores
         *  as 1 based.
         */
        public CT_Col GetColumn1Based(long index1, bool splitColumns)
        {
            CT_Cols colsArray = worksheet.GetColsArray(0);

            // Fetching the array is quicker than working on the new style
            //  list, assuming we need to read many of them (which we often do),
            //  and assuming we're not making many changes (which we're not)
            CT_Col[] cols = colsArray.GetColList().ToArray();
            for (int i = 0; i < cols.Length; i++)
            {
                CT_Col colArray = cols[i];
                long   colMin   = colArray.min;
                long   colMax   = colArray.max;
                if (colMin <= index1 && colMax >= index1)
                {
                    if (splitColumns)
                    {
                        if (colMin < index1)
                        {
                            insertCol(colsArray, colMin, (index1 - 1), new CT_Col[] { colArray });
                        }
                        if (colMax > index1)
                        {
                            insertCol(colsArray, (index1 + 1), colMax, new CT_Col[] { colArray });
                        }
                        colArray.min = (uint)(index1);
                        colArray.max = (uint)(index1);
                    }
                    return(colArray);
                }
            }
            return(null);
        }
コード例 #3
0
ファイル: ColumnHelper.cs プロジェクト: ruo2012/Npoi.Core
        public void CleanColumns()
        {
            this.newCols = new CT_Cols();

            CT_Cols        aggregateCols = new CT_Cols();
            List <CT_Cols> colsList      = worksheet.GetColsList();

            if (colsList == null)
            {
                return;
            }

            foreach (CT_Cols cols in colsList)
            {
                foreach (CT_Col col in cols.GetColList())
                {
                    CloneCol(aggregateCols, col);
                }
            }

            SortColumns(aggregateCols);

            CT_Col[] colArray = aggregateCols.GetColList().ToArray();
            SweepCleanColumns(newCols, colArray, null);

            int i = colsList.Count;

            for (int y = i - 1; y >= 0; y--)
            {
                worksheet.RemoveCols(y);
            }
            worksheet.AddNewCols();
            worksheet.SetColsArray(0, newCols);
        }
コード例 #4
0
ファイル: ColumnHelper.cs プロジェクト: flowbywind/npoi
 /**
  * Returns the Column at the given 1 based index.
  * POI default is 0 based, but the file stores
  *  as 1 based.
  */
 public CT_Col GetColumn1Based(long index1, bool splitColumns)
 {
     CT_Cols cols = worksheet.GetColsArray(0);
     CT_Col[] colArray = cols.GetColList().ToArray();
     foreach (CT_Col col in colArray)
     {
         long colMin = col.min;
         long colMax = col.max;
         if (colMin <= index1 && colMax >= index1)
         {
             if (splitColumns)
             {
                 if (colMin < index1)
                 {
                     insertCol(cols, colMin, (index1 - 1), new CT_Col[] { col });
                 }
                 if (colMax > index1)
                 {
                     insertCol(cols, (index1 + 1), colMax, new CT_Col[] { col });
                 }
                 col.min = (uint)(index1);
                 col.max = (uint)(index1);
             }
             return col;
         }
     }
     return null;
 }
コード例 #5
0
ファイル: TestXSSFColGrouping.cs プロジェクト: xewn/Npoi.Core
        public void TestNoColsWithoutWidthWhenGroupingAndCollapsing()
        {
            XSSFWorkbook wb    = new XSSFWorkbook();
            XSSFSheet    sheet = (XSSFSheet)wb.CreateSheet("test");

            sheet.SetColumnWidth(4, 5000);
            sheet.SetColumnWidth(5, 5000);

            sheet.GroupColumn((short)4, (short)5);

            sheet.SetColumnGroupCollapsed(4, true);

            CT_Cols cols = sheet.GetCTWorksheet().GetColsArray(0);

            //logger.log(POILogger.DEBUG, "test52186_2/cols:" + cols);

            wb    = XSSFTestDataSamples.WriteOutAndReadBack(wb, "testNoColsWithoutWidthWhenGroupingAndCollapsing");
            sheet = (XSSFSheet)wb.GetSheet("test");

            for (int i = 4; i <= 5; i++)
            {
                Assert.AreEqual(5000, sheet.GetColumnWidth(i), "Unexpected width of column " + i);
            }
            cols = sheet.GetCTWorksheet().GetColsArray(0);
            foreach (CT_Col col in cols.GetColList())
            {
                Assert.IsTrue(col.IsSetWidth(), "Col width attribute is unset: " + col.ToString());
            }
        }
コード例 #6
0
ファイル: ColumnHelper.cs プロジェクト: founshi/npoi
        public void CleanColumns()
        {
            TreeSet <CT_Col> trackedCols = new TreeSet <CT_Col>(CTColComparator.BY_MIN_MAX);
            CT_Cols          newCols     = new CT_Cols();

            CT_Cols[] colsArray = worksheet.GetColsList().ToArray();
            int       i         = 0;

            for (i = 0; i < colsArray.Length; i++)
            {
                CT_Cols  cols     = colsArray[i];
                CT_Col[] colArray = cols.GetColList().ToArray();
                foreach (CT_Col col in colArray)
                {
                    addCleanColIntoCols(newCols, col, trackedCols);
                }
            }
            for (int y = i - 1; y >= 0; y--)
            {
                worksheet.RemoveCols(y);
            }

            newCols.SetColArray(trackedCols.ToArray(new CT_Col[trackedCols.Count]));
            worksheet.AddNewCols();
            worksheet.SetColsArray(0, newCols);
            //this.newCols = new CT_Cols();

            //CT_Cols aggregateCols = new CT_Cols();
            //List<CT_Cols> colsList = worksheet.GetColsList();
            //if (colsList == null)
            //{
            //    return;
            //}

            //foreach (CT_Cols cols in colsList)
            //{
            //    foreach (CT_Col col in cols.GetColList())
            //    {
            //        CloneCol(aggregateCols, col);
            //    }
            //}

            //SortColumns(aggregateCols);

            //CT_Col[] colArray = aggregateCols.GetColList().ToArray();
            //SweepCleanColumns(newCols, colArray, null);

            //int i = colsList.Count;
            //for (int y = i - 1; y >= 0; y--)
            //{
            //    worksheet.RemoveCols(y);
            //}
            //worksheet.AddNewCols();
            //worksheet.SetColsArray(0, newCols);
        }
コード例 #7
0
ファイル: ColumnHelper.cs プロジェクト: founshi/npoi
        public CT_Cols addCleanColIntoCols(CT_Cols cols, CT_Col newCol)
        {
            // Performance issue. If we encapsulated management of min/max in this
            // class then we could keep trackedCols as state,
            // making this log(N) rather than Nlog(N). We do this for the initial
            // read above.
            TreeSet <CT_Col> trackedCols = new TreeSet <CT_Col>(CTColComparator.BY_MIN_MAX);

            trackedCols.AddAll(cols.GetColList());
            addCleanColIntoCols(cols, newCol, trackedCols);
            cols.SetColArray(trackedCols.ToArray(new CT_Col[0]));
            return(cols);
        }
コード例 #8
0
ファイル: ColumnHelper.cs プロジェクト: flowbywind/npoi
 public CT_Cols AddCleanColIntoCols(CT_Cols cols, CT_Col col)
 {
     CT_Cols newCols = new CT_Cols();
     foreach (CT_Col c in cols.GetColList())
     {
         CloneCol(newCols, c);
     }
     CloneCol(newCols, col);
     SortColumns(newCols);
     CT_Col[] colArray = newCols.GetColList().ToArray();
     CT_Cols returnCols = new CT_Cols();
     SweepCleanColumns(returnCols, colArray, col);
     colArray = returnCols.GetColList().ToArray();
     cols.SetColArray(colArray);
     return returnCols;
 }
コード例 #9
0
ファイル: TestXSSFColGrouping.cs プロジェクト: xewn/Npoi.Core
        public void TestNoColsWithoutWidthWhenGrouping()
        {
            XSSFWorkbook wb    = new XSSFWorkbook();
            XSSFSheet    sheet = (XSSFSheet)wb.CreateSheet("test");

            sheet.SetColumnWidth(4, 5000);
            sheet.SetColumnWidth(5, 5000);

            sheet.GroupColumn((short)4, (short)7);
            sheet.GroupColumn((short)9, (short)12);

            wb    = XSSFTestDataSamples.WriteOutAndReadBack(wb, "testNoColsWithoutWidthWhenGrouping");
            sheet = (XSSFSheet)wb.GetSheet("test");

            CT_Cols cols = sheet.GetCTWorksheet().GetColsArray(0);

            //logger.log(POILogger.DEBUG, "test52186/cols:" + cols);
            foreach (CT_Col col in cols.GetColList())
            {
                Assert.IsTrue(col.IsSetWidth(), "Col width attribute is unset: " + col.ToString());
            }
        }