예제 #1
0
파일: XLSX.cs 프로젝트: soravroyal/EPRTR
        private void MakeCells(XmlElement row, ref ArrayList resultRow, int lastRowIndex)
        {
            int lastColSeen = 0;

            foreach (XmlElement cell in XLSX.GetChildElements(row, "Cell"))
            {
                string colIndex = cell.GetAttribute("n");
                int    n        = 0;

                if (colIndex.Length > 0 && ((n = Int32.Parse(colIndex)) > 0))
                {
                    lastColSeen = n;
                }
                else
                {
                    lastColSeen++;
                }

                if (lastColSeen > 16384)
                {
                    throw new System.Exception("Cannot make more than 16384 columns; This is an Excel limitation");
                }

                while (resultRow.Count <= lastColSeen)
                {
                    resultRow.Add(null);
                }
                if (resultRow[lastColSeen] == null)
                {
                    resultRow[lastColSeen] = cell;
                }
            }
        }
예제 #2
0
파일: XLSX.cs 프로젝트: soravroyal/EPRTR
        private void MakeWorksheets(ref Hashtable resultWorksheets)
        {
            XmlElement workbook = XLSX.GetChildElement(document, "Workbook");

            int sheetNo = 0;

            foreach (XmlElement worksheet in XLSX.GetChildElements(workbook, "Worksheet"))
            {
                string sheetName = worksheet.GetAttribute("Name");
                if (sheetName.Length == 0)
                {
                    throw new System.Exception("Cannot create a worksheet without a name");
                }

                int lastRowSeen = 0;

                ResultWorksheet resultWorksheet = null;
                if (resultWorksheets.Contains(sheetName))
                {
                    resultWorksheet = (ResultWorksheet)resultWorksheets[sheetName];
                }
                else
                {
                    resultWorksheet = new ResultWorksheet(sheetName, new ArrayList());
                }

                foreach (XmlElement row in XLSX.GetChildElements(worksheet, "Row"))
                {
                    string rowIndex = row.GetAttribute("r");
                    int    n        = 0;

                    if (rowIndex.Length > 0 && ((n = Int32.Parse(rowIndex)) > 0))
                    {
                        lastRowSeen = n;
                    }
                    else
                    {
                        rowIndex = Convert.ToString(++lastRowSeen);
                    }

                    while (resultWorksheet.Matrix.Count <= lastRowSeen)
                    {
                        resultWorksheet.Matrix.Add(null);
                    }

                    ArrayList lastRow = (ArrayList)resultWorksheet.Matrix[lastRowSeen];
                    if (lastRow == null)
                    {
                        lastRow = new ArrayList();
                    }

                    MakeCells(row, ref lastRow, lastRowSeen);
                    resultWorksheet.Matrix[lastRowSeen] = lastRow;
                }
                resultWorksheet.Filename    = "worksheets/Sheet" + Convert.ToString(sheetNo) + ".xml";
                resultWorksheet.SheetId     = "rId" + Convert.ToString(sheetNo++);
                resultWorksheets[sheetName] = resultWorksheet;
            }
        }