Hi,
I am using Aspose.Cells to generate excel. I am facing some formatting issue. Text wrapping is not working for the header row. I have written the code for this purpose -
style.IsTextWrapped = true;
Also,Value in each cell is generated in text format. I need it in number format.
cells[count + 1, j + 1].Style.Number = 9;
Please find the below code that i am using for generating excel. Please help me in solving both these issues.
Aspose.Cells.License license = new Aspose.Cells.License();
license.SetLicense(HttpContext.Current.Server.MapPath("~\\License\\Aspose.Total.lic"));
Workbook workBook = new Workbook();
Aspose.Cells.Worksheet wsContent = workBook.Worksheets[0];
try
{
wsContent.Name = "Monthly Statistics Report";
Aspose.Cells.Cells cells = wsContent.Cells;
wsContent.Cells.SetColumnWidthPixel(0, 100);
cells[0, 0].PutValue("Month");
cells[0, 1].PutValue("Sent");
cells[0, 2].PutValue("Replied");
cells[0, 3].PutValue("Responded %");
cells[0, 4].PutValue("Very Sat.");
cells[0, 5].PutValue("Moderately Sat.");
cells[0, 6].PutValue("Slightly Sat.");
cells[0, 7].PutValue("Slightly Dissat.");
cells[0, 8].PutValue("Moderately Dissat.");
cells[0, 9].PutValue("Very Dissat.");
cells[0, 10].PutValue("Satisfied %");
Aspose.Cells.Style style = workBook.Styles[workBook.Styles.Add()];
style.Font.Color = System.Drawing.Color.White;
style.ForegroundColor = System.Drawing.Color.SteelBlue;
style.Font.IsBold = true;
style.IsTextWrapped = true;
style.Pattern = BackgroundType.Solid;
style.Borders[BorderType.TopBorder].Color = System.Drawing.Color.Black;
style.Borders[BorderType.BottomBorder].Color = System.Drawing.Color.Black;
style.Borders[BorderType.LeftBorder].Color = System.Drawing.Color.Black;
style.Borders[BorderType.RightBorder].Color = System.Drawing.Color.Black;
style.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin;
style.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;
style.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin;
style.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin;
style.HorizontalAlignment = TextAlignmentType.Center;
style.Number = 9;
for (int counter = 0; counter < 11; counter++)
{
wsContent.Cells.SetColumnWidthPixel(counter + 1, 70);
cells[0, counter].SetStyle(style);
cells[0, counter].Style.Font.Name = "Calibri";
cells[0, counter].Style.Font.Size = 11;
}
int count = 1;
foreach (GridViewRow grvRow in grdReport.Rows)
{
cells[count, 0].PutValue(grvRow.Cells[0].Text);
cells[count, 1].PutValue(grvRow.Cells[1].Text);
cells[count, 2].PutValue(grvRow.Cells[2].Text);
cells[count, 3].PutValue(grvRow.Cells[3].Text);
cells[count, 4].PutValue(grvRow.Cells[4].Text);
cells[count, 5].PutValue(grvRow.Cells[5].Text);
cells[count, 6].PutValue(grvRow.Cells[6].Text);
cells[count, 7].PutValue(grvRow.Cells[7].Text);
cells[count, 8].PutValue(grvRow.Cells[8].Text);
cells[count, 9].PutValue(grvRow.Cells[9].Text);
cells[count, 10].PutValue(grvRow.Cells[10].Text);
// &=cells[count,0].ToString()(numeric);
cells[count, 0].Style.HorizontalAlignment = TextAlignmentType.Left;
for (int j = 0; j < 11; j++)
{
cells[count, j].Style.Font.Name = "Calibri";
cells[count, j].Style.Font.Size = 11;
cells[count + 1, j + 1].Style.Number = 9;
cells[count, j + 1].Style.HorizontalAlignment = TextAlignmentType.Right;
cells[count, j].Style.Borders[BorderType.TopBorder].Color = System.Drawing.Color.Black;
cells[count, j].Style.Borders[BorderType.BottomBorder].Color = System.Drawing.Color.Black;
cells[count, j].Style.Borders[BorderType.LeftBorder].Color = System.Drawing.Color.Black;
cells[count, j].Style.Borders[BorderType.RightBorder].Color = System.Drawing.Color.Black;
cells[count, j].Style.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin;
cells[count, j].Style.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;
cells[count, j].Style.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin;
cells[count, j].Style.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin;
}
count++;
}
workBook.Save("Monthly Statistics for " + Common.General.GetTravelAgencySubQuestion(Convert.ToInt32(ddlCategory.SelectedValue)) + ".xlsx", FileFormatType.Default, Aspose.Cells.SaveType.OpenInBrowser, this.Response);
HttpContext.Current.Response.End();
}
catch (Exception ex)
{
throw ex;
}