Esempio n. 1
0
        private void AddExportXSD(string pdeFilePath, string stnName, PdeExports exportData)
        {
            Excel.Application app = new Excel.Application();
            app.Visible = false;
            Excel.Workbook workbook = app.Workbooks.Open(pdeFilePath);

            try
            {
                Excel.XmlMaps maps = workbook.XmlMaps;

                // delete old mapp
                DeleteOldMap(maps, ProntoDoc.Framework.CoreObject.FrameworkConstants.PdeExportedMapName);

                // gen new xsd
                string xsdFile = GenExportedXSD(stnName, exportData);

                // add new map
                Excel.XmlMap map = maps.Add(xsdFile);
                map.Name = ProntoDoc.Framework.CoreObject.FrameworkConstants.PdeExportedMapName;

                // save
                workbook.Save();

                // delete xsd file
                ProntoDoc.Framework.Utils.FileHelper.DeleteFile(xsdFile);
            }
            finally
            {
                ((Excel._Workbook)workbook).Close();
                ((Excel._Application)app).Quit();
            }
        }
Esempio n. 2
0
 public bool ReadExportInfo(Workbook workbook)
 {
     foreach (CustomXMLPart curXmlPart in workbook.CustomXMLParts)
     {
         if (curXmlPart.BuiltIn)
         {
             continue;
         }
         XmlObject customObject = ObjectSerializeHelper.Deserialize <XmlObject>(curXmlPart.XML);
         if (customObject.ContentType == ContentType.PdeExportItem)
         {
             String     xmlcontent = customObject.Content;
             PdeExports pdeExports = ObjectSerializeHelper.Deserialize <PdeExports>(xmlcontent);
             this.exportItems = pdeExports.items;
             return(true);
         }
     }
     return(false);
 }
Esempio n. 3
0
        private string GenExportedXSD(string stnName, PdeExports pdeExports)
        {
            // initialize schema
            string schemaNamespace = "http://www.w3.org/2001/XMLSchema";

            Schema.XmlSchema expSchema = new Schema.XmlSchema();

            // create STN node (root node)
            Schema.XmlSchemaSequence stnElementSequence = CreateSequenceElement(expSchema, stnName);
            Schema.XmlSchemaAll      field = null;
            Schema.XmlSchemaAll      table = null;

            foreach (DomainExportItem expDomain in pdeExports.Items)
            {
                if (expDomain.Items == null || expDomain.Items.Count == 0)
                {
                    continue;
                }

                foreach (ExportItem expItem in expDomain.Items)
                {
                    if (!expItem.IsUsed)
                    {
                        continue;
                    }

                    switch (expItem.MapType)
                    {
                    case MapType.SingleCell:
                        #region field
                        if (field == null)
                        {
                            field = CreateElement(stnElementSequence, MarkupConstant.PdeExportField);
                        }

                        // create field informations
                        Schema.XmlSchemaElement fieldElement = new Schema.XmlSchemaElement();
                        fieldElement.Name           = expItem.EncodeTreeNodeName;
                        fieldElement.SchemaTypeName = new System.Xml.XmlQualifiedName(GetXsdDataType(expItem.DataType), schemaNamespace);
                        field.Items.Add(fieldElement);
                        #endregion
                        break;

                    case MapType.Table:
                        #region table
                        if (table == null)
                        {
                            table = CreateElement(stnElementSequence, MarkupConstant.PdeExportTable);
                        }

                        // create table informations
                        Schema.XmlSchemaElement tableElement = new Schema.XmlSchemaElement();
                        tableElement.MinOccurs       = 0;
                        tableElement.MaxOccursString = "unbounded";
                        tableElement.Name            = expItem.EncodeTreeNodeName;
                        table.Items.Add(tableElement);

                        Schema.XmlSchemaComplexType tableElementType = new Schema.XmlSchemaComplexType();
                        tableElementType.IsMixed = false;
                        Schema.XmlSchemaAll tableElementAll = new Schema.XmlSchemaAll();
                        tableElementType.Particle = tableElementAll;
                        tableElement.SchemaType   = tableElementType;

                        // gen column informations
                        if (expItem.Columns != null && expItem.Columns.Count > 0)
                        {
                            foreach (ColumnExportItem col in expItem.Columns)
                            {
                                if (!col.IsUsed)
                                {
                                    continue;
                                }
                                Schema.XmlSchemaElement colElement = new Schema.XmlSchemaElement();
                                colElement.Name           = col.EncodeTreeNodeName;
                                colElement.SchemaTypeName = new System.Xml.XmlQualifiedName(GetXsdDataType(col.DataType), schemaNamespace);
                                tableElementAll.Items.Add(colElement);
                            }
                        }
                        #endregion
                        break;

                    case MapType.Chart:
                        break;

                    default:
                        break;
                    }
                }
            }

            // complie schema
            expSchema.Compile(new Schema.ValidationEventHandler(ValidationEventHandler));

            // write schem to xsd file
            string xsdFilePath = string.Format("{0}\\{1}.xsd", AssetManager.FileAdapter.TemporaryFolderPath, Guid.NewGuid().ToString());
            using (System.IO.FileStream stream = new System.IO.FileStream(xsdFilePath, System.IO.FileMode.Create))
            {
                expSchema.Write(stream);
                stream.Close();
            }

            return(xsdFilePath);
        }
Esempio n. 4
0
        private PdeExports GetExportedData(Excel.Workbook wExcel)
        {
            if (wExcel == null)
            {
                return(null);
            }
            InternalBookmark ibm       = GetPdeInternalBookmark(wExcel);
            PdeExports       export    = new PdeExports();
            DomainExportItem expDomain = new DomainExportItem();

            expDomain.DomainName = "DomainName";

            #region get tags
            foreach (Excel.Name name in wExcel.Names)
            {
                ExportItem expItem = new ExportItem();
                expItem.IsUsed = false; // default is not used
                bool   isAdd   = false;
                string strName = name.Name;
                if (string.IsNullOrWhiteSpace(strName))
                {
                    continue;
                }

                // update field
                if (strName.EndsWith(BaseProntoMarkup.KeySelect))
                {
                    expItem.MapType  = MapType.SingleCell;
                    expItem.DataType = GetPdeDataType(strName, ibm);
                    isAdd            = true;
                }

                // update table
                if (strName.EndsWith(BaseProntoMarkup.KeyTable))
                {
                    expItem.MapType = MapType.Table;
                    Excel.Range      range      = name.RefersToRange;
                    Excel.ListObject listColumn = range.ListObject;
                    expItem.Columns = new System.Collections.Generic.List <ColumnExportItem>();

                    // update columns
                    foreach (Excel.ListColumn lstCol in listColumn.ListColumns)
                    {
                        ColumnExportItem expColumn = new ColumnExportItem();
                        expColumn.ColumnName   = lstCol.Name;
                        expColumn.ExcelName    = lstCol.Range.Name.Name;
                        expColumn.TreeNodeName = expColumn.ExcelName;
                        expColumn.ExcelAddress = lstCol.Range.AddressLocal;
                        expColumn.ParentName   = strName;
                        expColumn.DomainName   = expDomain.DomainName;
                        expColumn.IsUsed       = false;
                        expColumn.DataType     = GetPdeDataType(expColumn.ExcelName, ibm);
                        expItem.Columns.Add(expColumn);
                    }
                    isAdd = true;
                }

                if (isAdd)
                {
                    expItem.ExcelSheetName = name.RefersToRange.Parent.Name;
                    expItem.ExcelName      = strName;
                    expItem.ExcelAddress   = name.RefersToRange.AddressLocal;
                    expItem.TreeNodeName   = expItem.ExcelName;
                    expItem.ParentName     = expDomain.DomainName;
                    expDomain.Items.Add(expItem);
                }
            }
            #endregion

            #region get charts
            foreach (Excel.Worksheet sheet in wExcel.Sheets)
            {
                Excel.ChartObjects charts = sheet.ChartObjects(Type.Missing);
                if (charts != null)
                {
                    foreach (Excel.ChartObject chart in charts)
                    {
                        ExportItem exportItem = new ExportItem();
                        exportItem.MapType        = MapType.Chart;
                        exportItem.ExcelName      = chart.Name;
                        exportItem.TreeNodeName   = exportItem.ExcelName;
                        exportItem.ParentName     = expDomain.DomainName;
                        exportItem.ExcelSheetName = sheet.Name;

                        exportItem.Chart      = new ExportItemChart();
                        exportItem.Chart.Name = chart.Name;
                        string filePath = AssetManager.FileAdapter.GenRandomFilePath(ChartExtension);
                        chart.Chart.Export(filePath, "JPG");
                        exportItem.Chart.Content = ProntoDoc.Framework.Utils.FileHelper.FileToBase64(filePath);
                        System.IO.File.Delete(filePath);

                        expDomain.Items.Add(exportItem);
                    }
                }
            }
            #endregion

            export.Items = new System.Collections.Generic.List <DomainExportItem>();
            export.Items.Add(expDomain);
            return(export);
        }