Beispiel #1
0
        public short SelectSheet(String sheetName)
        {
            if (sheetName != null && sheetName.CompareTo("") != 0)
            {
                IEnumerable worksheets = (IEnumerable)GxExcelUtils.GetPropValue(ef, "Worksheets");
                foreach (object ews in worksheets)
                {
                    if (((string)GxExcelUtils.GetPropValue(ews, "Name")).Equals(sheetName))
                    {
                        GxExcelUtils.SetPropValue(worksheets, "ActiveWorksheet", ews);
                        return(0);
                    }
                }

                object ws = GxExcelUtils.Invoke(worksheets, "Add", new object[] { sheetName });
                GxExcelUtils.SetPropValue(worksheets, "ActiveWorksheet", ws);

                return(0);
            }
            else
            {
                this.errCod         = 5;
                this.errDescription = "Invalid worksheet name";
                return(errCod);
            }
        }
Beispiel #2
0
        public ExcelCells(IGxError errAccess, object ef, int row, int col, int height, int width)
        {
            this.errAccess = errAccess;
            object cells = GxExcelUtils.GetPropValue(GxExcelUtils.GetPropValue(GxExcelUtils.GetPropValue(ef, "Worksheets"), "ActiveWorksheet"), "Cells");

            cr = GxExcelUtils.Invoke(cells, "GetSubrangeAbsolute", new Object[] { row, col, row + height, col + width });
            GxExcelUtils.SetPropValue(cr, "Merged", true);
        }
Beispiel #3
0
        public short Open(String fileName)
        {
            try
            {
                GXLogging.Debug(log, "GetType " + nmspace + ".ExcelFile");
                Type classType = ass.GetType(nmspace + ".ExcelFile", false, true);
                ef = Activator.CreateInstance(classType);

                GxFile file = new GxFile(Path.GetDirectoryName(fileName), fileName, GxFileType.Private);
                if (!String.IsNullOrEmpty(template))
                {
                    GxFile templateFile = new GxFile(Path.GetDirectoryName(template), template);
                    if (templateFile.Exists())
                    {
                        GXLogging.Debug(log, "Opening Template " + template);
                        var stream = templateFile.GetStream();
                        stream.Position = 0;

                        GxExcelUtils.Invoke(ef, "LoadXls", new object[] { stream });
                    }
                    else
                    {
                        errCod         = 4;
                        errDescription = "Invalid template.";
                        return(errCod);
                    }
                }
                else if (file.Exists())
                {
                    var stream = file.GetStream();
                    stream.Position = 0;

                    GxExcelUtils.Invoke(ef, "LoadXls", new object[] { stream });
                }
                else
                {
                    object worksheets = GxExcelUtils.GetPropValue(ef, "Worksheets");

                    object ws = GxExcelUtils.Invoke(worksheets, "Add", new object[] { "Sheet1" });
                    GxExcelUtils.SetPropValue(worksheets, "ActiveWorksheet", ws);
                }
                xlsFileName = fileName;
            }
            catch (Exception e)
            {
                GXLogging.Error(log, "Error opening " + fileName, e);
                errCod         = 10;
                errDescription = "Could not open file." + e.Message + (e.InnerException != null ? e.InnerException.Message:"");
                return(errCod);
            }
            return(0);
        }
Beispiel #4
0
        public short Clear()
        {
            IEnumerable rows = (IEnumerable)GxExcelUtils.GetPropValue(GxExcelUtils.GetPropValue(GxExcelUtils.GetPropValue(ef, "Worksheets"), "ActiveWorksheet"), "Rows");

            ArrayList toDelete = new ArrayList();

            foreach (object er in rows)
            {
                toDelete.Add(er);
            }
            for (int i = toDelete.Count - 1; i >= 0; i--)
            {
                GxExcelUtils.Invoke(toDelete[i], "Delete", null);
            }

            return(0);
        }
Beispiel #5
0
 public short Save()
 {
     try
     {
         GxFile       file    = new GxFile(Path.GetDirectoryName(xlsFileName), xlsFileName, GxFileType.Private);
         MemoryStream content = new MemoryStream();
         GxExcelUtils.Invoke(ef, "SaveXls", new object[] { content });
         content.Position = 0;
         file.Create(content);
     }
     catch (Exception e)
     {
         GXLogging.Error(log, "Error saving " + xlsFileName, e);
         errCod         = 12;
         errDescription = "Could not save file." + e.Message;
         return(-1);
     }
     return(0);
 }
Beispiel #6
0
 public short RenameSheet(String sheetName)
 {
     GxExcelUtils.SetPropValue(GxExcelUtils.GetPropValue(GxExcelUtils.GetPropValue(ef, "Worksheets"), "ActiveWorksheet"), "Name", sheetName);
     return(0);
 }
Beispiel #7
0
        public short Init(string previousMsgError)
        {
            try
            {
                GXLogging.Debug(log, "Init");

                if (ass == null)
                {
                    if (nmspace == null)
                    {
                        ass = loadAssembly(Path.Combine(GxContext.StaticPhysicalPath(), "GemBox.Spreadsheet.dll"));
                        if (ass == null)
                        {
                            ass = loadAssembly(Path.Combine(GxContext.StaticPhysicalPath(), @"bin\GemBox.Spreadsheet.dll"));
                        }
                        if (ass != null)
                        {
                            nmspace = "GemBox.Spreadsheet";
                        }
                        else
                        {
                            if (ass == null)
                            {
                                ass = loadAssembly(Path.Combine(GxContext.StaticPhysicalPath(), @"GemBox.ExcelLite.dll"));
                            }
                            if (ass == null)
                            {
                                ass = loadAssembly(Path.Combine(GxContext.StaticPhysicalPath(), @"bin\GemBox.ExcelLite.dll"));
                            }
                            if (ass != null)
                            {
                                nmspace = "GemBox.ExcelLite";
                            }
                        }
                    }
                    else
                    {
                        ass = loadAssembly(Path.Combine(GxContext.StaticPhysicalPath(), nmspace + ".dll"));
                        if (ass == null)
                        {
                            ass = loadAssembly(Path.Combine(GxContext.StaticPhysicalPath(), @"bin\" + nmspace + ".dll"));
                        }
                    }
                    GXLogging.Debug(log, "nmspace:" + nmspace);

                    if (ass == null)
                    {
                        errCod         = 99;
                        errDescription = previousMsgError + "Error Loading GemBox.ExcelLite.dll, GemBox.Spreadsheet.dll";
                        return(errCod);
                    }
                    else if (license != null)
                    {
                        try
                        {
                            GxExcelUtils.InvokeStatic(ass, nmspace + ".SpreadsheetInfo", "SetLicense", new object[] { license });
                        }
                        catch (Exception e)
                        {
                            GXLogging.Error(log, @"Error setting license.", e);
                        }
                    }
                }
                return(0);
            }
            catch (FileNotFoundException fe)
            {
                GXLogging.Error(log, "Error Loading " + fe.FileName, fe);
                errCod         = 99;
                errDescription = fe.Message;
                return(errCod);
            }
        }
Beispiel #8
0
        private object GetFont(object crinstance)
        {
            object cell = GxExcelUtils.Invoke(crinstance, "get_Item", new object[] { 0, 0 });

            return(GxExcelUtils.GetPropValue(GxExcelUtils.GetPropValue(cell, "Style"), "Font"));
        }