Esempio n. 1
0
        public byte[] Render(Element report)
        {
            _workbook = new Workbook();
            _ws       = _workbook.Worksheets.Add("Report");

            RecurseBuildRowsCols(report, 0, 0);
            _rows.Add(0);
            _rows.Sort(delegate(decimal d1, decimal d2) { return(decimal.Compare(d1, d2)); });
            _cols.Add(0);
            _cols.Sort(delegate(decimal d1, decimal d2) { return(decimal.Compare(d1, d2)); });

            for (int i = 1; i < _rows.Count; i++)
            {
                _ws.Rows[i - 1].Height = (int)((_rows[i] - _rows[i - 1]) * _lineHeight);
            }

            for (int i = 1; i < _cols.Count; i++)
            {
                _ws.Columns[i - 1].Width = (int)((_cols[i] - _cols[i - 1]) * _colWidth);
            }

            RecurseRender(report, 0, 0);

            MemoryStream ms = new MemoryStream();

            BIFF8Writer.WriteWorkbookToStream(_workbook, ms);
            return(ms.ToArray());
        }
Esempio n. 2
0
        public static void WriteToResponse(Workbook theWorkBook, string FileName, HttpResponse resp)
        {
            System.IO.MemoryStream theStream = new System.IO.MemoryStream();

            BIFF8Writer.WriteWorkbookToStream(theWorkBook, theStream);

            byte[] byteArr = (byte[])Array.CreateInstance(typeof(byte), theStream.Length);

            theStream.Position = 0;
            theStream.Read(byteArr, 0, (int)theStream.Length);
            theStream.Close();

            resp.Clear();

            resp.AddHeader("content-disposition", "attachment; filename=" + FileName);

            resp.BinaryWrite(byteArr);

            resp.End();
        }
    public void formatExcel(DataSet ds, DataSet d, string strCultureCode)
    {
        Infragistics.Documents.Excel.Workbook workbook = new Infragistics.Documents.Excel.Workbook();
        int rowIndex;

        foreach (DataTable dt in ds.Tables)
        {
            Infragistics.Documents.Excel.Worksheet worksheet = workbook.Worksheets.Add(dt.TableName);
            DataRowCollection tableRows = d.Tables[0].Rows;
            for (int colindex = 0; colindex < dt.Columns.Count; colindex++)
            {
                worksheet.Columns[colindex].CellFormat.Font.Bold = ExcelDefaultableBoolean.True;
                #region Column Section
                worksheet.Rows[0].Cells[colindex].CellFormat.Font.Bold = ExcelDefaultableBoolean.True;
                worksheet.Rows[0].Cells[colindex].CellFormat.Alignment = HorizontalCellAlignment.Center;
                worksheet.Rows[0].Cells[0].Value = dt.Columns[0].ColumnName;
                worksheet.Rows[0].Cells[1].Value = dt.Columns[1].ColumnName;
                worksheet.Rows[0].Cells[2].Value = dt.Columns[2].ColumnName;
                worksheet.Rows[0].Cells[3].Value = dt.Columns[3].ColumnName;
                worksheet.Rows[0].Cells[4].Value = dt.Columns[4].ColumnName;
                worksheet.Rows[0].Cells[5].Value = dt.Columns[5].ColumnName;
                worksheet.Rows[0].Cells[6].Value = dt.Columns[6].ColumnName;
                worksheet.Rows[0].Cells[7].Value = dt.Columns[7].ColumnName;
                worksheet.Rows[0].Cells[8].Value = dt.Columns[8].ColumnName;
                worksheet.Rows[0].Cells[9].Value = dt.Columns[9].ColumnName;
                #endregion
            }
            #region Row Section
            rowIndex = 1;
            foreach (DataRow dr in dt.Rows)
            {
                worksheet.Rows[rowIndex].CellFormat.Font.Bold = ExcelDefaultableBoolean.False;
                Infragistics.Documents.Excel.WorksheetRow row = worksheet.Rows[rowIndex++];

                for (int colIndex = 0; colIndex < dr.ItemArray.Length; colIndex++)
                {
                    row.Cells[colIndex].Value = dr.ItemArray[colIndex];
                }
            }
            #endregion
        }
        string            fileName       = string.Empty;
        string            formatFileName = DateTime.Now.ToString("yyyyMMdd") + "-" + DateTime.Now.ToString("HHmmss");
        DataRowCollection tableRow       = d.Tables[0].Rows;
        foreach (DataRow row in tableRow)
        {
            string hostName = row[0].ToString();
            fileName += "CASLinkExport-" + hostName + "-" + strCultureCode + "-" + SessionState.User.Id.ToString() + "-" + formatFileName + ".xls";
        }
        workbook.ActiveWorksheet = workbook.Worksheets[0];
        MemoryStream stream = new MemoryStream();
        BIFF8Writer.WriteWorkbookToStream(workbook, stream);
        Response.Clear();
        Response.ClearContent();
        Response.ClearHeaders();
        Response.AddHeader("content-disposition", "attachment;filename=" + fileName);
        Response.ContentType     = "application/ms-excel";
        Response.ContentEncoding = System.Text.Encoding.UTF8;
        Response.AppendHeader("Content-Length", stream.Length.ToString());
        EnableViewState = false;
        Response.OutputStream.Write(stream.ToArray(), 0, Convert.ToInt32(stream.Length));
        Response.End();
    }