예제 #1
0
        private void AddDataSetToCsv(DataSetContent set, CsvWriter csvWriter)
        {
            foreach (var head in set.Headers)
            {
                csvWriter.WriteField(head);
            }

            csvWriter.NextRecord();

            foreach (var row in set.Rows)
            {
                foreach (var value in row)
                {
                    csvWriter.WriteField(value);
                }

                csvWriter.NextRecord();
            }
        }
예제 #2
0
        protected override void AddDataSetToExcel(ExcelPackage inPackage, DataSetContent content)
        {
            var ws = inPackage.Workbook.Worksheets.Add(
                string.IsNullOrEmpty(content.Name) ? "NoNamedList" : content.Name);
            var propNum = 0;


            var groupColumns = content.GroupColumns;

            var grouping = GetMergedRows(content.Rows, groupColumns, groupColumns);
            var headers  = ChangeHeadersOrder(content.Headers, groupColumns);

            foreach (string header in headers)
            {
                ws.Cells[1, ++propNum].Value = header;
            }

            using (ExcelRange rng = ws.Cells[1, 1, 1, propNum])
            {
                rng.Style.Font.Bold        = true;
                rng.Style.Fill.PatternType = ExcelFillStyle.Solid;
                rng.Style.Fill.BackgroundColor.SetColor(Color.LightGray);
            }

            var sizes = new Dictionary <int, double>();

            FillGroup(ws, grouping, 1, 2, sizes);

            var i = grouping.Keys.Sum(key => key.SpanCount);

            ws.Cells[1, 1, i, propNum].AutoFitColumns(5, 50);

            for (int j = 1; j <= propNum; j++)
            {
                ws.Column(j).Style.WrapText = true;
            }

            for (int j = 1; j <= sizes.Count; j++)
            {
                ws.Column(j).Width = sizes[j];
            }
        }
예제 #3
0
        protected virtual void AddDataSetToExcel(ExcelPackage inPackage, DataSetContent content)
        {
            var ws = inPackage.Workbook.Worksheets.Add(
                string.IsNullOrEmpty(content.Name) ? "NoNamedList" : content.Name);
            var propNum = 0;

            foreach (string header in content.Headers)
            {
                ws.Cells[1, ++propNum].Value = header;
            }

            using (ExcelRange rng = ws.Cells[1, 1, 1, propNum])
            {
                rng.Style.Font.Bold        = true;
                rng.Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
                rng.Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.LightGray);
            }

            int i = 0;

            foreach (var row in content.Rows)
            {
                i++;
                int j = 0;

                foreach (var value in row)
                {
                    j++;
                    ws.Cells[i + 1, j].SetObjValue(value, "");
                }
            }

            ws.Cells[1, 1, i, propNum].AutoFitColumns(5, 50);

            for (int j = 1; j <= propNum; j++)
            {
                ws.Column(j).Style.WrapText = true;
            }

            // return inPackage;
        }
예제 #4
0
        private string AddDataSetToTelegView(string tmRep, DataSetContent content)
        {
            tmRep = tmRep.Insert(tmRep.Length,
                                 Environment.NewLine + Environment.NewLine + $"_{content.Name}_");

            tmRep = tmRep.Insert(tmRep.Length, Environment.NewLine +
                                 string.Join(" | ",
                                             content.Headers.Select(head =>
                                                                    Regex.Replace(head, @"([[*_])",
                                                                                  @"\$1"))));

            foreach (var row in content.Rows)
            {
                tmRep = tmRep.Insert(tmRep.Length, Environment.NewLine + string.Join(" | ", row
                                                                                     .Select(val =>
                                                                                             val is string strVal
                                                               ? Regex.Replace(strVal,
                                                                               @"([[*_])", @"\$1")
                                                               : val)));
            }

            return(tmRep);
        }