I'm attempting to convert an Excel workbook with angled table headers to an image, but the results are not at all what I was expecting. Here's a simple sample:
var excelEngine = new ExcelEngine();
var app = excelEngine.Excel;
app.DefaultVersion = ExcelVersion.Excel2013;
var workbook = app.Workbooks.Create(1);
var worksheet = workbook.Worksheets[0];
for (int c = 1; c < 13; c++)
{
var range = worksheet.Range[2, c];
range.Text = "Test " + c;
range.CellStyle.Rotation = 45;
range.CellStyle.Color = Color.ForestGreen;
range.CellStyle.Font.RGBColor = Color.Black;
range.BorderAround(ExcelLineStyle.Medium, ExcelKnownColors.Grey_80_percent);
}
for (int r = 3; r < 7; r++)
{
for (int c = 1; c < 13; c++)
{
var range = worksheet.Range[r, c];
range.Text = string.Format("({0},{1})", r, c);
range.CellStyle.Color = Color.White;
range.CellStyle.Font.RGBColor = Color.Black;
range.BorderAround(ExcelLineStyle.Medium, ExcelKnownColors.Grey_25_percent);
}
}
// Save an Excel file.
workbook.SaveAs("test.xlsx");
// Convert to image and save.
var image = worksheet.ConvertToImage(1, 1, 15, 15, ImageType.Bitmap, imageStream, System.Drawing.Imaging.EmfType.EmfOnly);
image.Save("text.png", System.Drawing.Imaging.ImageFormat.Png);
I've attached a zip file with screenshots of the Excel file and the output PNG. The Excel file looks exactly like I want it to, but the converted image looks nothing like the Excel file. The column headers are not angled, and the text that is supposed to be inside those columns appears to be floating above the columns in the row above.
Am I doing something wrong, or are angled columns just not supported by the ConvertToImage method?
Thanks!
Ken
Attachment:
Screenshots_92add7ae.zip