示例#1
0
        //carica i dati presenti nel file specificato
        public bool LoadFile(string filePath)
        {
            bool   result         = false;
            string targetFileName = "content.xml";

            m_Tables       = new List <ROdsTable>();
            m_CurrentTable = null;

            //TODO : se il file è aperto genera un errore. Si potrebbe evitare la cosa usando una copia temporanea
            //TODO : evitare eccezzione se il file ods non esiste?
            using (System.IO.Compression.ZipArchive za = System.IO.Compression.ZipFile.OpenRead(filePath))
            {
                foreach (System.IO.Compression.ZipArchiveEntry entry in za.Entries)
                {
                    if (entry.FullName.ToUpper() == targetFileName.ToUpper())
                    {
                        using (System.IO.StreamReader sr = new System.IO.StreamReader(entry.Open(), Encoding.UTF8))
                        {
                            this.m_xml = sr.ReadToEnd();
                            result     = true;
                        }
                        break;
                    }
                }
            }

            this.LoadXml();
            return(result);
        }
示例#2
0
        //imposta la tabella corrente in base al nome dato
        private void SetCurrentTable(string TableName)
        {
            string name = TableName.ToLower();

            if (!(m_CurrentTable is null))
            {
                if (m_CurrentTable.Name.ToLower() != name)
                {
                    m_CurrentTable = null;
                }
            }

            if (m_CurrentTable is null)
            {
                foreach (ROdsTable tbl in m_Tables)
                {
                    if (tbl.Name.ToLower() == name)
                    {
                        m_CurrentTable = tbl;
                        break;
                    }
                }
            }
        }
示例#3
0
        private void LoadXml()
        {
            XmlDocument xd = new XmlDocument();
            XmlNodeList tablesList;
            int         iRow          = 1;
            int         iColumn       = 1;
            string      CellValue     = ""; //valore
            string      CellValueText = ""; //valore in
            string      CellValueType = ""; //valore visualizzato
            XmlNode     att;
            XmlNode     textp;
            ROdsTable   currentTable;

            xd.LoadXml(m_xml);

            //lista tabelle in file
            tablesList = xd.GetElementsByTagName("table:table");
            foreach (XmlNode tbl in tablesList) //analisi tabelle
            {
                iRow              = 1;
                currentTable      = new ROdsTable();
                currentTable.Name = GetNodeAttribute(tbl, "table:name");
                foreach (XmlNode item in tbl) //analisi elementi in tabella
                {
                    if (item.Name == "table:table-row")
                    { //identificata linea
                        iColumn = 0;

                        att = item.Attributes.GetNamedItem("table:number-rows-repeated");
                        if (!(att is null))
                        {
                            iRow = iRow + Convert.ToInt32(att.Value) - 1;
                        }

                        foreach (XmlNode itemRow in item)
                        { //analisi celle in linea
                            if (itemRow.Name == "table:table-cell")
                            {
                                CellValueType = "";
                                CellValue     = "";
                                CellValueText = "";

                                att = itemRow.Attributes.GetNamedItem("office:value-type");
                                if (!(att is null))
                                {
                                    CellValueType = att.Value;
                                }
                                att = itemRow.Attributes.GetNamedItem("office:value");
                                if (!(att is null))
                                {
                                    CellValue = att.Value;
                                }

                                textp = itemRow.FirstChild;
                                if (!(textp is null))
                                {
                                    CellValueText = textp.InnerText;
                                }

                                iColumn++;

                                //TODO : manca supporto per tipi diversi
                                if ((CellValue != "") || (CellValueText != ""))
                                {
                                    currentTable.Cells.Add(new ROdsCell()
                                    {
                                        ValueType = CellValueType,
                                        Value     = CellValue,
                                        ValueText = CellValueText,
                                        Row       = iRow,
                                        Column    = iColumn,
                                    });
                                }

                                att = itemRow.Attributes.GetNamedItem("table:number-columns-repeated");
                                if (!(att is null))
                                {
                                    iColumn = iColumn + Convert.ToInt32(att.Value) - 1;
                                }

                                att = itemRow.Attributes.GetNamedItem("table:number-columns-spanned");
                                if (!(att is null))
                                {
                                    iColumn = iColumn + Convert.ToInt32(att.Value) - 1;
                                }
                            }
                        }
                        iRow++;
                    }
                    else if (item.Name == "table:table-header-rows")
                    {
                        throw new Exception("File type error. Unsupported Rows Header.");
                    }
                    else if (item.Name == "table:table-row-group")
                    {
                        throw new Exception("File type error. Unsupported Row Group.");
                    }
                }
                m_Tables.Add(currentTable);
            }
        }