Ejemplo n.º 1
0
        public static void SetHexColor(XElementData data, int r, int g, int b)
        {
            var colorData = data.Element("a", "srgbClr");

            if (colorData == null)
            {
                colorData = data.Add("a", "srgbClr");
            }
            colorData.SetAttributeValue("val", string.Format("{0:X2}{1:X2}{2:X2}", r, g, b));
        }
Ejemplo n.º 2
0
        public static void SetPercentageColor(XElementData data, int r, int g, int b)
        {
            var colorData = data.Element("a", "scrgbClr");

            if (colorData == null)
            {
                colorData = data.Add("a", "scrgbClr");
            }
            colorData["r"] = r.ToString();
            colorData["g"] = g.ToString();
            colorData["b"] = b.ToString();
        }
Ejemplo n.º 3
0
        private void ReadContents()
        {
            DefaultRowHeight = double.Parse(data.Element("sheetFormatPr")["defaultRowHeight"], NumberFormatInfo.InvariantInfo);
            var cols = data.Element("cols") ?? data.Element("sheetFormatPr").AddAfterSelf("cols");

            SheetColumns = new SheetColumns(cols);
            sheetData    = new SheetData(data.Element("sheetData"), this, SheetColumns);
            SheetView    = new SheetViews(data.Element("sheetViews"));
            canDraw      = TryLoadDrawings();
        }
Ejemplo n.º 4
0
        public Worksheet(XElementData data, IWorkbook workbook, string worksheetFolder, string name, int sheetId)
        {
            this.data              = data;
            this.Workbook          = workbook;
            this.relationshipsData = new XElementData(XDocument.Load(string.Format("{0}/_rels/sheet{1}.xml.rels", worksheetFolder, sheetId)).Root);
            this.worksheetFolder   = worksheetFolder;
            this.sheetId           = sheetId;
            Name = name;
            ReadContents();
            var dimension = data.Element("dimension");

            if (dimension != null)
            {
                dimension.Remove(); // clear dimension attribute - will be recalculated
            }
        }
Ejemplo n.º 5
0
        private void ReadContents()
        {
            data = new XElementData(XDocument.Load(path).Root);
            var relationshipsData = new XElementData(XDocument.Load(string.Format("{0}/_rels/workbook.xml.rels", Path.GetDirectoryName(path))).Root);

            foreach (var worksheetElement in data.Element("sheets").Descendants("sheet"))
            {
                var id   = worksheetElement.AttributeValue("r", "id");
                var name = worksheetElement["name"];
                if (!id.StartsWith("rId"))
                {
                    throw new InvalidDataException(string.Format("Invalid sheet id [{0}]", id));
                }

                int sheetId         = int.Parse(id.Substring("rId".Length), NumberFormatInfo.InvariantInfo);
                var target          = relationshipsData.Descendants("Relationship").Single(r => r["Id"] == id)["Target"];
                var worksheetPath   = string.Format("{0}/{1}", xlFolder, target);
                var worksheetFolder = Path.GetDirectoryName(worksheetPath);
                var worksheetData   = new XElementData(XDocument.Load(worksheetPath).Root);
                worksheets.Add(new Worksheet(worksheetData, this, worksheetFolder, name, sheetId));
            }
        }