Beispiel #1
0
        private UnZipper GetUnZipper(Stream stream)
        {
            UnZipper result = null;

            try
            {
                result = new UnZipper(stream);
            }
            catch (Exception ex)
            {
                throw new NotSupportedException("It is not xlsx file.", ex);
            }
            return(result);
        }
Beispiel #2
0
        private IWorksheet[] GetSheetList(UnZipper unzip, List <string> fileNames)
        {
            var sharedStrings       = GetSharedStrings(unzip, fileNames);
            List <XLSXSheet> result = new List <XLSXSheet>();

            if (fileNames.Contains(XLSXCommon.Workbook))
            {
                var workbook = unzip.GetXLSXPart(XLSXCommon.Workbook);
                foreach (var item in workbook.Descendants(XLSXCommon.ExcelNamespace + XLSXCommon.XML_Sheet))
                {
                    result.Add(new XLSXSheet(item.Attribute(XLSXCommon.XML_Name).Value,
                                             item.Attribute(XLSXCommon.XML_SheetId).Value, unzip, sharedStrings, fileNames));
                }
            }
            return(result.ToArray());
        }
Beispiel #3
0
        private static Dictionary <string, string> GetSharedStrings(UnZipper unzip, List <string> fileNames)
        {
            Dictionary <string, string> dic = new Dictionary <string, string>();

            if (fileNames.Contains(XLSXCommon.SharedStrings))
            {
                var sharedStrings = unzip.GetXLSXPart(XLSXCommon.SharedStrings);
                int count         = 0;
                var si            = XLSXCommon.ExcelNamespace + XLSXCommon.XML_SI;
                var t             = XLSXCommon.ExcelNamespace + XLSXCommon.XML_T;

                foreach (var items in sharedStrings.Descendants(si)
                         .Select(i => i.Descendants(t))
                         .Where(i => !i.IsEmpty()))
                {
                    dic.Add(count.ToString(), string.Join("", items.Select(i => i.Value)));
                    count++;
                }
            }
            return(dic);
        }
Beispiel #4
0
        public XLSXSheet(string name, string id, UnZipper unzip, Dictionary <string, string> sharedStrings, List <string> fileNames)
        {
            Name = name;
            Rows = new Dictionary <uint, IRow>();
            var xml_sheetFileName = string.Format(XLSXCommon.Sheet, id);

            if (!fileNames.Any(i => i.EqualsIgnoreCase(xml_sheetFileName)))
            {
                return;
            }
            {
                var element = unzip.GetXLSXPart(xml_sheetFileName);
                foreach (var row in element.Descendants(XLSXCommon.ExcelNamespace + XLSXCommon.XML_Row))
                {
                    var indexStr = row.Attribute(XLSXCommon.XML_R);
                    var index    = int.Parse(indexStr.Value) - 1;
                    Rows.Add((uint)index, new XLSXRow(row, sharedStrings));
                }
                FillMergeCells(GetMergeCells(element));
            }
        }