Пример #1
0
 /// <summary>
 /// Creates a new instance of the ExcelWorkbook class.  For internal use only!
 /// </summary>
 /// <param name="xlPackage">The parent package</param>
 protected internal ExcelWorkbook(ExcelPackage xlPackage)
 {
     _xlPackage = xlPackage;
     //  Create a NamespaceManager to handle the default namespace, 
     //  and create a prefix for the default namespace:
     var nt = new NameTable();
     _nsManager = new XmlNamespaceManager(nt);
     _nsManager.AddNamespace("d", ExcelPackage.schemaMain);
 }
Пример #2
0
        public static string[] ReadColumnsNames(ExcelPackage package, TableDescriptor descriptor)
        {
            var worksheet = package.Workbook.Worksheets[descriptor.SheetName];
            var columnCount = GetColumnCount(descriptor, worksheet);

            var columns = new List<string>(columnCount);
            for (var columnIndex = 1; columnIndex <= columnCount; columnIndex++)
            {
                var cell = worksheet.Cell(descriptor.HeaderRow, columnIndex);
                columns.Add(cell.Value);
            }
            return columns.ToArray();
        }
Пример #3
0
 /// <summary>
 /// Provides access to all the office document properties.
 /// </summary>
 /// <param name="xlPackage"></param>
 public OfficeProperties(ExcelPackage xlPackage)
 {
     _xlPackage = xlPackage;
     //  Create a NamespaceManager to handle the default namespace, 
     //  and create a prefix for the default namespace:
     var nt = new NameTable();
     _nsManager = new XmlNamespaceManager(nt);
     // default namespace
     _nsManager.AddNamespace("d", ExcelPackage.schemaMain);
     _nsManager.AddNamespace("vt", SchemaVt);
     // extended properties (app.xml)
     _nsManager.AddNamespace("xp", SchemeExtended);
     // custom properties
     _nsManager.AddNamespace("ctp", SchemaCustom);
     // core properties
     _nsManager.AddNamespace("cp", SchemaCore);
     // core property namespaces
     _nsManager.AddNamespace("dc", SchemaDc);
     _nsManager.AddNamespace("dcterms", SchemaDcTerms);
     _nsManager.AddNamespace("dcmitype", SchemaDcmiType);
     _nsManager.AddNamespace("xsi", SchemaXsi);
 }
Пример #4
0
        public static IEnumerable<string[]> Read(ExcelPackage package, TableDescriptor descriptor)
        {
            #region Check
            if (!descriptor.CanRead)
            {
                throw new ArgumentException(string.Format("Descriptor '{0}' doesn't support read", descriptor.SheetName), "descriptors");
            }
            #endregion
            {
                {
                    var worksheet = package.Workbook.Worksheets[descriptor.SheetName];
                    var columnCount = GetColumnCount(descriptor, worksheet);

                    var rowIndex = descriptor.BeginRow;
                    do
                    {
                        #region Check end
                        if (descriptor.Key.Items.Any(keyCol => !string.IsNullOrEmpty(worksheet.Cell(rowIndex, keyCol).Value)))
                        {
                            goto NEXT;
                        }
                        break;
                        NEXT:
                        #endregion
                        var array = new string[columnCount];
                        for (var columnIndex = 1; columnIndex <= columnCount; columnIndex++)
                        {
                            var cell = worksheet.Cell(rowIndex, columnIndex);
                            array[columnIndex - 1] = cell.Value;
                        }
                        yield return array;
                        rowIndex++;
                    } while (true);
                }
            }
        }