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); } }
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); }
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); }
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); }
public short RenameSheet(String sheetName) { GxExcelUtils.SetPropValue(GxExcelUtils.GetPropValue(GxExcelUtils.GetPropValue(ef, "Worksheets"), "ActiveWorksheet"), "Name", sheetName); return(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")); }