Exemplo n.º 1
0
        public void ResetWorkBookRows()
        {
            foreach (var sh in Sheets)
            {
                ExcelSheetSchema sheet = sh.Value;

                foreach (var rw in sheet.Rows)
                {
                    ExcelRowSchema row = rw.Value;
                    row.Processed = 0;
                }
            }
        }
Exemplo n.º 2
0
        public ExcelWorkBookSchema(XmlSchema schema, IFormulaEvaluator formulaEvaluator)
        {
            if (schema.Items.Count > 1)
            {
                throw new ArgumentException("Source schema is only allowed to have one root node");
            }

            XmlSchemaElement workbook = (XmlSchemaElement)schema.Items[0];

            this.Namespace = workbook.QualifiedName.Namespace;
            this.Name      = workbook.QualifiedName.Name;

            if (!(workbook.SchemaType is XmlSchemaComplexType))
            {
                throw new ArgumentException("Nodes bellow root node must be of record type");
            }

            //first must be complex type containing sequences of Sheet type objects
            XmlSchemaComplexType tp = (XmlSchemaComplexType)workbook.SchemaType;

            XmlSchemaSequence seq = (XmlSchemaSequence)tp.Particle;

            for (int i = 0; i < seq.Items.Count; i++)
            {
                XmlSchemaElement sheet = (XmlSchemaElement)seq.Items[i];

                int sheetIndex = GetIndex(sheet.Annotation, sheet.Name);

                if (sheetIndex == -1)
                {
                    sheetIndex = i;
                }

                ExcelSheetSchema eSheet = new ExcelSheetSchema
                {
                    Name      = sheet.Name,
                    Namespace = sheet.QualifiedName.Namespace,
                    Index     = sheetIndex
                };

                this.Sheets.Add(sheet.Name, eSheet);



                XmlSchemaComplexType sheetType = (XmlSchemaComplexType)sheet.SchemaType;

                XmlSchemaSequence sheetSequence = (XmlSchemaSequence)sheetType.Particle;

                for (int x = 0; x < sheetSequence.Items.Count; x++)
                {
                    XmlSchemaElement row = (XmlSchemaElement)sheetSequence.Items[x];

                    int rowIndex = GetIndex(row.Annotation, row.Name);

                    if (rowIndex == -1)
                    {
                        rowIndex = x;
                    }

                    XmlSchemaComplexType rowType = (XmlSchemaComplexType)row.SchemaType;

                    ExcelRowSchema eRow = new ExcelRowSchema
                    {
                        Name       = row.Name,
                        Namespace  = row.QualifiedName.Namespace,
                        Index      = rowIndex,
                        Occurrence = row.MaxOccursString == "unbounded"? -1:(int)row.MaxOccurs
                    };

                    if (rowType.Attributes.Count > 0)
                    {
                        foreach (XmlSchemaAttribute item in rowType.Attributes)
                        {
                            XmlSchemaSimpleType sp = item.AttributeSchemaType;

                            //  XmlSchemaDatatype tp;
                            //  XmlTypeCode.DateTime
                            int cellIndex = GetIndex(item.Annotation, item.Name);

                            if (cellIndex > -1)
                            {
                                eRow.Cells.Add(item.Name, new ExcelCellSchema
                                {
                                    XmlType          = GetExcelType(sp.Datatype.TypeCode),
                                    Index            = cellIndex,
                                    Name             = item.Name,
                                    NodeType         = 'A',
                                    FormulaEvaluator = formulaEvaluator
                                });
                            }
                        }
                    }

                    if (rowType.Particle != null)
                    {
                        XmlSchemaSequence rowSequence = (XmlSchemaSequence)rowType.Particle;

                        foreach (XmlSchemaElement item in rowSequence.Items)
                        {
                            int cellIndex = GetIndex(item.Annotation, item.Name);

                            if (cellIndex > -1)
                            {
                                eRow.Cells.Add(item.Name, new ExcelCellSchema
                                {
                                    XmlType  = GetExcelType(item.ElementSchemaType.Datatype.TypeCode),
                                    Index    = cellIndex,
                                    Name     = item.Name,
                                    NodeType = 'E'
                                });
                            }
                        }
                    }

                    eSheet.Rows.Add(row.Name, eRow);
                }
            }
        }