Пример #1
0
        private bool ImportPdeTag(PdeContentItem pdeContentItem, string domainName, string tableExcelName, string columnExcelName)
        {
            if (pdeContentItem == null || pdeContentItem.ExportData == null || pdeContentItem.ExportData.Items == null)
            {
                return(false);
            }

            // validate export domain information
            DomainExportItem expDomain = pdeContentItem.ExportData.Items.FirstOrDefault(
                c => string.Equals(c.DomainName, domainName, StringComparison.OrdinalIgnoreCase));

            if (expDomain == null || expDomain.Items == null)
            {
                return(false);
            }

            // validate export item information
            ExportItem expItem = expDomain.Items.FirstOrDefault(
                c => string.Equals(c.ExcelName, tableExcelName, StringComparison.OrdinalIgnoreCase));

            if (expItem == null)
            {
                return(false);
            }

            // validate export column
            if (!string.IsNullOrWhiteSpace(columnExcelName))
            {
                if (expItem.Columns == null)
                {
                    return(false);
                }
                ColumnExportItem expColumn = expItem.Columns.FirstOrDefault(
                    c => string.Equals(c.ExcelName, columnExcelName, StringComparison.OrdinalIgnoreCase));
                if (expColumn == null)
                {
                    return(false);
                }
                expColumn.IsUsed = true;
            }
            expItem.IsUsed = true;
            return(true);
        }
Пример #2
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);
        }