Beispiel #1
0
 public short Open(String xlName)
 {
     this.fileName = xlName;
     if (document != null && closed)
     {
         document = null;
     }
     if (!string.IsNullOrEmpty(xlName) && checkExcelDocument())
     {
         closed = false;
         try
         {
             if (GXServices.Instance == null || GXServices.Instance.Get(GXServices.STORAGE_SERVICE) == null)
             {
                 if (!Path.IsPathRooted(this.fileName))
                 {
                     this.fileName = Path.Combine(GxContext.StaticPhysicalPath(), this.fileName);
                 }
             }
             else
             {
                 this.fileName = this.fileName.Replace("\\", "/");
             }
         }
         catch (Exception e)
         {
             GXLogging.Warn(log, "Setting Rooted Path on " + this.fileName, e);
         }
         return(document.Open(this.fileName));
     }
     else
     {
         return(document.ErrCode);
     }
 }
        public void CopyVbaInfoFrom([NotNull] IExcelDocument excelDocument)
        {
            ThrowIfSpreadsheetDisposed();
            var part = ((ExcelDocument)excelDocument).spreadsheetDocument.WorkbookPart.VbaProjectPart;

            if (part == null)
            {
                return;
            }
            spreadsheetDocument.WorkbookPart.AddPart(part);
        }
Beispiel #3
0
 private void CopySecondaryWorksheets(IExcelDocument templateDocument, IExcelDocument targetDocument)
 {
     foreach (var index in Enumerable.Range(1, templateDocument.GetWorksheetCount() - 1))
     {
         var worksheet           = templateDocument.GetWorksheet(index);
         var name                = templateDocument.GetWorksheetName(index);
         var innerTemplateEngine = new TemplateEngine(new ExcelTable(worksheet), logger);
         var targetWorksheet     = targetDocument.AddWorksheet(name);
         var innerTableBuilder   = new TableBuilder(new ExcelTable(targetWorksheet), new TableNavigator(new CellPosition("A1"), logger));
         innerTemplateEngine.Render(innerTableBuilder, new {});
     }
 }
        public ExcelWorksheet(IExcelDocument excelDocument, WorksheetPart worksheetPart, IExcelDocumentStyle documentStyle, IExcelSharedStrings excelSharedStrings, ILog logger)
        {
            worksheet               = worksheetPart.Worksheet;
            ExcelDocument           = excelDocument;
            this.documentStyle      = documentStyle;
            this.excelSharedStrings = excelSharedStrings;
            this.logger             = logger;
            rowsCache               = new TreeDictionary <uint, Row>();
            var sheetData = worksheet.GetFirstChild <SheetData>();

            if (sheetData != null)
            {
                rowsCache.AddAll(sheetData.Elements <Row>().Select(x => new C5.KeyValuePair <uint, Row>(x.RowIndex, x)));
            }
        }
Beispiel #5
0
        public bool checkExcelDocument()
        {
            if (Document == null)
            {
#if !NETCORE
                if (this.fileName.EndsWith(Constants.EXCEL2003Extension) || this.template.EndsWith(Constants.EXCEL2003ExtensionTemplate))
                {
                    if (document == null || document.ErrCode == 99)
                    {
                        GXLogging.Debug(log, "GeneXus.Office.ExcelLite.ExcelDocument");
                        string initErrDesc = (document != null && document.ErrCode == 99) ? document.ErrDescription : "";
                        document          = new GeneXus.Office.ExcelLite.ExcelDocument();
                        document.ReadOnly = ReadOnly;
                        document.Init(initErrDesc);
                    }
                    if (document == null || document.ErrCode != 0) //Automation
                    {
                        GXLogging.Debug(log, "Interop.GXOFFICE2Lib.ExcelDocumentClass");
                        document          = new IExcelDocumentWrapper(new Interop.GXOFFICE2Lib.ExcelDocumentClass());
                        document.ReadOnly = ReadOnly;
                        document.Init("");
                    }
                }
                else
#endif
                {
                    document          = new GeneXus.Office.ExcelGXEPPlus.ExcelDocument();
                    document.ReadOnly = ReadOnly;
                }

                if (!String.IsNullOrEmpty(defPath))
                {
                    setDefaultPath(defPath);
                }
                if (!String.IsNullOrEmpty(template))
                {
                    Template = template;
                }
                ErrDisplay = errDisplay;
                if (!String.IsNullOrEmpty(delimiter))
                {
                    Delimiter = delimiter;
                }
                AutoFit = autoFit;
            }

            return(document != null && document.ErrCode != 99);
        }