Exemplo n.º 1
0
        private static bool MatchFont(XDocument sXDoc, XElement xf, CellDfn cell)
        {
            if (((int?)xf.Attribute(SSNoNamespace.applyFont) == 0 ||
                 xf.Attribute(SSNoNamespace.applyFont) == null) &&
                (cell.Bold == null || cell.Bold == false) &&
                (cell.Italic == null || cell.Italic == false))
            {
                return(true);
            }
            if (((int?)xf.Attribute(SSNoNamespace.applyFont) == 0 ||
                 xf.Attribute(SSNoNamespace.applyFont) == null) &&
                (cell.Bold == true ||
                 cell.Italic == true))
            {
                return(false);
            }
            var fontId = (int)xf.Attribute(SSNoNamespace.fontId);
            var font   = sXDoc
                         .Root
                         .Element(S.fonts)
                         .Elements(S.font)
                         .ElementAt(fontId);
            var fabFont = new XElement(S.font,
                                       cell.Bold == true ? new XElement(S.b) : null,
                                       cell.Italic == true ? new XElement(S.i) : null);
            var match = XNode.DeepEquals(font, fabFont);

            return(match);
        }
Exemplo n.º 2
0
        private void SetDailyReportInfo(WorksheetDfn worksheet, List <DailyReportInfo> dailyReportInfo)
        {
            RowDfn         row   = new RowDfn();
            List <CellDfn> cells = new List <CellDfn>();

            for (int i = 1; i <= dailyReportInfo.Count; i++)
            {
                CellDfn cell1 = new CellDfn();
                cell1.Value = dailyReportInfo[i - 1].Header;
                cell1.Bold  = true;
                cells.Add(cell1);

                CellDfn cell2 = new CellDfn();
                cell2.Value = dailyReportInfo[i - 1].Value;
                cells.Add(cell2);

                CellDfn cell3 = new CellDfn();
                cell3.Value = "";
                cells.Add(cell3);

                if (i % 3 == 0)
                {
                    row.Cells = cells.ToList();
                    Rows.Add(row);
                    cells = new List <CellDfn>();
                    row   = new RowDfn();
                }
            }
        }
Exemplo n.º 3
0
        private void SetReportBudgetRows(WorksheetDfn worksheet, List <DailyReportBudgetData> reportBudgetData)
        {
            RowDfn         row;
            List <CellDfn> cells;

            foreach (var budgetData in reportBudgetData)
            {
                cells = new List <CellDfn>();
                row   = new RowDfn();


                CellDfn cell = new CellDfn();
                cell.Value = budgetData.LineItem;
                cells.Add(cell);

                foreach (var milestone in budgetData.Milestones)
                {
                    CellDfn milestoneCell = new CellDfn();
                    milestoneCell.Value = milestone;
                    cells.Add(milestoneCell);
                }
                row.Cells = cells.ToList();
                Rows.Add(row);
            }
        }
Exemplo n.º 4
0
        private static bool CompareStyles(XDocument sXDoc, XElement xf, CellDfn cell)
        {
            var matchFont      = MatchFont(sXDoc, xf, cell);
            var matchAlignment = MatchAlignment(sXDoc, xf, cell);
            var matchFormat    = MatchFormat(sXDoc, xf, cell);

            return(matchFont && matchAlignment && matchFormat);
        }
        private void SetColumnHeaders(WorksheetDfn worksheet, ProductionSheetData productionSheetData)
        {
            List <CellDfn> columnHeaders = new List <CellDfn>();

            foreach (var header in productionSheetData.ColumnHeaders)
            {
                CellDfn cell = new CellDfn();
                cell.Value = header;
                cell.Bold  = true;
                columnHeaders.Add(cell);
            }
            worksheet.ColumnHeadings = columnHeaders;
        }
Exemplo n.º 6
0
        private void SetActivityLogHeader(WorksheetDfn worksheet, List <string> activityLogHeaders)
        {
            RowDfn         row   = new RowDfn();
            List <CellDfn> cells = new List <CellDfn>();

            foreach (var header in activityLogHeaders)
            {
                CellDfn cell = new CellDfn();
                cell.Value = header;
                cell.Bold  = true;
                cells.Add(cell);
            }
            row.Cells = cells;
            Rows.Add(row);
        }
Exemplo n.º 7
0
        private static bool MatchFormat(XDocument sXDoc, XElement xf, CellDfn cell)
        {
            if ((int?)xf.Attribute(SSNoNamespace.applyNumberFormat) != 1 &&
                cell.FormatCode == null)
            {
                return(true);
            }
            if (xf.Attribute(SSNoNamespace.applyNumberFormat) == null &&
                cell.FormatCode != null)
            {
                return(false);
            }
            var numFmtId = (int)xf.Attribute(SSNoNamespace.numFmtId);
            int?nfi      = null;

            if (cell.FormatCode != null)
            {
                if (CellDfn.StandardFormats.ContainsKey(cell.FormatCode))
                {
                    nfi = CellDfn.StandardFormats[cell.FormatCode];
                }
                if (nfi == numFmtId)
                {
                    return(true);
                }
            }
            var numFmts = sXDoc
                          .Root
                          .Element(S.numFmts);

            if (numFmts == null)
            {
                return(false);
            }
            var numFmt = numFmts
                         .Elements(S.numFmt)
                         .FirstOrDefault(numFmtElement =>
                                         (int)numFmtElement.Attribute(SSNoNamespace.numFmtId) == numFmtId);

            if (numFmt == null)
            {
                return(false);
            }
            var styleFormatCode = (string)numFmt.Attribute(SSNoNamespace.formatCode);
            var match           = styleFormatCode == cell.FormatCode;

            return(match);
        }
Exemplo n.º 8
0
        private static bool MatchAlignment(XDocument sXDoc, XElement xf, CellDfn cell)
        {
            if ((int?)xf.Attribute(SSNoNamespace.applyAlignment) == 0 ||
                (xf.Attribute(SSNoNamespace.applyAlignment) == null) &&
                cell.HorizontalCellAlignment == null)
            {
                return(true);
            }
            if (xf.Attribute(SSNoNamespace.applyAlignment) == null &&
                cell.HorizontalCellAlignment != null)
            {
                return(false);
            }
            var alignment = (string)xf.Element(S.alignment).Attribute(SSNoNamespace.horizontal);
            var match     = alignment == cell.HorizontalCellAlignment.ToString().ToLower();

            return(match);
        }
        private void SetRowData(WorksheetDfn worksheet, ProductionSheetData productionSheetData)
        {
            List <RowDfn> rows = new List <RowDfn>();

            foreach (var dataRow in productionSheetData.DataRows)
            {
                RowDfn         row   = new RowDfn();
                List <CellDfn> cells = new List <CellDfn>();

                foreach (var cellData in dataRow)
                {
                    CellDfn cell = new CellDfn();
                    cell.Value = cellData;
                    cells.Add(cell);
                }

                row.Cells = cells;
                rows.Add(row);
            }
            worksheet.Rows = rows;
        }
Exemplo n.º 10
0
        private void SetColumnHeaders(WorksheetDfn worksheet)
        {
            List <CellDfn> columnHeaders = new List <CellDfn>();

            for (int i = 0; i < 13; i++)
            {
                CellDfn cell = new CellDfn();

                if (i == 6)
                {
                    cell.Value = "DAILY REPORT SHEET";
                    cell.Bold  = true;
                    columnHeaders.Add(cell);
                }
                else
                {
                    cell.Value = "-";
                    columnHeaders.Add(cell);
                }
            }
            worksheet.ColumnHeadings = columnHeaders;
        }
Exemplo n.º 11
0
        private static int GetFontId(XDocument sXDoc, CellDfn cell)
        {
            var fonts = sXDoc.Root.Element(S.fonts);

            if (fonts == null)
            {
                fonts = new XElement(S.fonts,
                                     new XAttribute(SSNoNamespace.count, 1),
                                     new XElement(S.font,
                                                  cell.Bold == true ? new XElement(S.b) : null,
                                                  cell.Italic == true ? new XElement(S.i) : null));
                sXDoc.Root.Add(fonts);
                return(0);
            }
            var font = new XElement(S.font,
                                    cell.Bold == true ? new XElement(S.b) : null,
                                    cell.Italic == true ? new XElement(S.i) : null);

            fonts.Add(font);
            var count = (int)fonts.Attribute(SSNoNamespace.count);

            fonts.SetAttributeValue(SSNoNamespace.count, count + 1);
            return(count);
        }
Exemplo n.º 12
0
        private static int GetCellStyle(SpreadsheetDocument sDoc, CellDfn cell)
        {
            var sXDoc = sDoc.WorkbookPart.WorkbookStylesPart.GetXDocument();
            var match = sXDoc
                        .Root
                        .Element(S.cellXfs)
                        .Elements(S.xf)
                        .Select((e, i) => new
            {
                Element = e,
                Index   = i,
            })
                        .FirstOrDefault(xf => CompareStyles(sXDoc, xf.Element, cell));

            if (match != null)
            {
                return(match.Index);
            }

            // if no match, then create a style
            var newId = CreateNewStyle(sXDoc, cell, sDoc);

            return(newId);
        }
Exemplo n.º 13
0
        private static int CreateNewStyle(XDocument sXDoc, CellDfn cell, SpreadsheetDocument sDoc)
        {
            XAttribute applyFont = null;
            XAttribute fontId    = null;

            if (cell.Bold == true || cell.Italic == true)
            {
                applyFont = new XAttribute(SSNoNamespace.applyFont, 1);
                fontId    = new XAttribute(SSNoNamespace.fontId, GetFontId(sXDoc, cell));
            }
            XAttribute applyAlignment = null;
            XElement   alignment      = null;

            if (cell.HorizontalCellAlignment != null)
            {
                applyAlignment = new XAttribute(SSNoNamespace.applyAlignment, 1);
                alignment      = new XElement(S.alignment,
                                              new XAttribute(SSNoNamespace.horizontal, cell.HorizontalCellAlignment.ToString().ToLower()));
            }
            XAttribute applyNumberFormat = null;
            XAttribute numFmtId          = null;

            if (cell.FormatCode != null)
            {
                if (CellDfn.StandardFormats.ContainsKey(cell.FormatCode))
                {
                    applyNumberFormat = new XAttribute(SSNoNamespace.applyNumberFormat, 1);
                    numFmtId          = new XAttribute(SSNoNamespace.numFmtId, CellDfn.StandardFormats[cell.FormatCode]);
                }
                else
                {
                    applyNumberFormat = new XAttribute(SSNoNamespace.applyNumberFormat, 1);
                    numFmtId          = new XAttribute(SSNoNamespace.numFmtId, GetNumFmtId(sXDoc, cell.FormatCode));
                }
            }
            var newXf = new XElement(S.xf,
                                     applyFont,
                                     fontId,
                                     applyAlignment,
                                     alignment,
                                     applyNumberFormat,
                                     numFmtId);
            var cellXfs = sXDoc
                          .Root
                          .Element(S.cellXfs);

            if (cellXfs == null)
            {
                cellXfs = new XElement(S.cellXfs,
                                       new XAttribute(SSNoNamespace.count, 1),
                                       newXf);
                return(0);
            }
            else
            {
                var currentCount = (int)cellXfs.Attribute(SSNoNamespace.count);
                cellXfs.SetAttributeValue(SSNoNamespace.count, currentCount + 1);
                cellXfs.Add(newXf);
                return(currentCount);
            }
        }
Exemplo n.º 14
0
        private void SetActivityLogRows(WorksheetDfn worksheet, List <ActivityLogEntryData> activityLogEntry)
        {
            RowDfn         row;
            List <CellDfn> cells;

            foreach (var activityLog in activityLogEntry)
            {
                cells = new List <CellDfn>();
                row   = new RowDfn();

                CellDfn from = new CellDfn();
                from.Value = activityLog.From;
                cells.Add(from);

                CellDfn to = new CellDfn();
                to.Value = activityLog.To;
                cells.Add(to);

                CellDfn elapsedTime = new CellDfn();
                elapsedTime.Value = activityLog.ElapsedTime;
                cells.Add(elapsedTime);

                CellDfn cumTime = new CellDfn();
                cumTime.Value = activityLog.CumulativeTime;
                cells.Add(cumTime);

                CellDfn depth = new CellDfn();
                depth.Value = activityLog.Depth;
                cells.Add(depth);

                CellDfn mudWeight = new CellDfn();
                mudWeight.Value = activityLog.MudWeight;
                cells.Add(mudWeight);

                CellDfn activity = new CellDfn();
                activity.Value = activityLog.Activity;
                cells.Add(activity);

                CellDfn milestone = new CellDfn();
                milestone.Value = activityLog.Milestone;
                cells.Add(milestone);

                CellDfn unplanned_planned = new CellDfn();
                unplanned_planned.Value = activityLog.Unplanned_Planned;
                cells.Add(unplanned_planned);

                CellDfn hasNPT = new CellDfn();
                hasNPT.Value = activityLog.HasNpt;
                cells.Add(hasNPT);

                CellDfn NPTReference = new CellDfn();
                NPTReference.Value = activityLog.NptReference;
                cells.Add(NPTReference);

                CellDfn descrption = new CellDfn();
                descrption.Value = activityLog.Description;
                cells.Add(descrption);

                row.Cells = cells.ToList();
                Rows.Add(row);
            }
        }