Ejemplo n.º 1
0
        //public void Generate(string xml, HttpResponseBase resp)
        //{
        //    var data = new MemoryStream();

        //    resp.ContentType = ContentType;
        //    resp.HeaderEncoding = Encoding.UTF8;
        //    resp.AppendHeader("Content-Disposition", "attachment;filename=my_report.xlsx");
        //    resp.AppendHeader("Cache-Control", "max-age=0");
        //    Generate(xml, data);

        //    data.WriteTo(resp.OutputStream);
        //}


        private void headerPrint(ExcelXmlParser parser)
        {
            cols = parser.getColumnsInfo("head");

            int[] widths = parser.getWidths();
            this.cols_stat = widths.Length;



            int sumWidth = 0;

            for (int i = 0; i < widths.Length; i++)
            {
                sumWidth += widths[i];
            }

            if (parser.getWithoutHeader() == false)
            {
                ExcelFont font = wb.CreateFont("Arial", 10);
                font.Bold = true;
                if (headerTextColor != "FF000000")
                {
                    font.Color = headerTextColor;
                }

                ExcelBorder border = getBorder();


                for (uint row = 1; row <= cols.Length; row++)
                {
                    //   sheet.Rows[row].Height = 22.5;
                    for (uint col = 1; col <= cols[row - 1].Length; col++)
                    {
                        // trick before font
                        //sheet.Cells[row, col].Style.SetAlignmentCenter = true;
                        sheet.Cells[row, col, true].IsHead = true;

                        sheet.Cells[row, col, true].Style.Font = font;//if bold font assigned after border - all table will be bold, weird, find out later

                        sheet.Cells[row, col].Style.Border = border;
                        sheet.Columns[col].Width           = widths[col - 1] / scale;
                        String name = cols[row - 1][col - 1].GetName();
                        if (bgColor != "FFFFFFFF")
                        {
                            sheet.Cells[row, col, true].Style.Fill.ForegroundColor = bgColor;
                        }

                        ///TODO:
                        ///font color, merge cells, alignment
                        sheet.Cells[row, col, true].Value = name;
                        colsNumber = (int)col;
                    }
                }
                headerOffset = cols.Length;



                /*  for (int col = 0; col < cols.Length; col++) {
                 *    for (int row = 0; row < cols[col].Length; row++) {
                 *        int cspan = cols[col][row].GetColspan();
                 *        if (cspan > 0) {
                 *            sheet.mergeCells(row, col, row + cspan - 1, col);
                 *        }
                 *        int rspan = cols[col][row].GetRowspan();
                 *        if (rspan > 0) {
                 *            sheet.mergeCells(row, col, row, col + rspan - 1);
                 *        }
                 *    }
                 * }*/
            }
        }
Ejemplo n.º 2
0
        private void headerPrint(ExcelXmlParser parser)
        {
            cols = parser.getColumnsInfo("head");
            //Widths
            int[] widths = parser.getWidths();
            if (this.Widths != null)
            {
                foreach (var index in this.Widths.Keys)
                {
                    if (index >= 0 && index < widths.Length)
                    {
                        widths[index] = Widths[index];
                    }
                }
            }
            this.cols_stat = widths.Length;



            int sumWidth = 0;

            for (int i = 0; i < widths.Length; i++)
            {
                sumWidth += widths[i];
            }

            if (parser.getWithoutHeader() == false)
            {
                ExcelFont font = wb.CreateFont(FontFamily, HeaderFontSize);
                font.Bold = true;
                if (HeaderTextColor != "FF000000")
                {
                    font.Color = HeaderTextColor;
                }

                ExcelBorder border = getBorder();


                for (uint row = 1; row <= cols.Length; row++)
                {
                    sheet.Rows[row].Height = RowHeight;
                    for (uint col = 1; col <= cols[row - 1].Length; col++)
                    {
                        sheet.Cells[row, col].Style.Font = font;//if bold font assigned after border - all table will be bold, weird, find out later

                        sheet.Cells[row, col].Style.Border = border;

                        sheet.Columns[col].Width = widths[col - 1] / scale;
                        String name = cols[row - 1][col - 1].GetName();
                        if (BGColor != "FFFFFFFF")
                        {
                            sheet.Cells[row, col].Style.Fill.ForegroundColor = BGColor;
                        }



                        ///TODO:
                        ///font color, merge cells, alignment
                        sheet.Cells[row, col].Value = name;
                        colsNumber = (int)col;
                    }
                }
                headerOffset = cols.Length;
            }
        }