Aspose.Cells 7.3.1.2
Windows XP.
Excel 2007.
.NET 3.5
When using workbook.copy and then saving a file as .xlsx the rotation angle of ticklabels is gone. Also, chart legend is slightly off. See image.
bad_formatting does not have diagonal ticklabels, it is the result of copy and save as .xlsx
good_formatting is .xls and is ok.
pre_merge is before the copy and is ok.
Workbook wb = new Workbook();
Worksheet sheet = wb.Worksheets[0];
Cells cells = sheet.Cells;
cells[0, 0].Value = “one”;
cells[1, 0].Value = “two”;
cells[2, 0].Value = “three”;
cells[0, 1].Value = 10;
cells[1, 1].Value = 20;
cells[2, 1].Value = 30;
cells[0, 2].Value = 30;
cells[1, 2].Value = 20;
cells[2, 2].Value = 10;
int chartIndex = sheet.Charts.Add(ChartType.Column, 0, 0, 10, 10);
Chart chart = sheet.Charts[chartIndex];
int sIndex = chart.NSeries.Add(“B1:B3”, true);
Series series1 = chart.NSeries[sIndex];
int sIndex2 = chart.NSeries.Add(“C1:C3”, true);
Series series2 = chart.NSeries[sIndex2];
chart.Title.Text = “This Is The Chart Title”;
//chart.Title.TextHorizontalAlignment = TextAlignmentType.Left;
//chart.Title.Width = 100;
//chart.Title.X = 1;
chart.Title.Font.Color = Color.Blue;
chart.Title.Font.Size = 10;
chart.Title.Font.IsBold = true;
chart.Title.Font.Name = “Arial”;
chart.Title.Font.Underline = FontUnderlineType.Single;
//chart.Title.IsAutomaticSize = false;
//chart.Title.AutoScaleFont = false;
chart.Title.X = 0;
chart.Title.Y = 0;
chart.Title.TextVerticalAlignment = TextAlignmentType.Left;
chart.Title.TextHorizontalAlignment = TextAlignmentType.Left;
chart.Legend.Font.Size = 7;
chart.Legend.Position = LegendPositionType.NotDocked;
chart.Legend.Y = 0;
chart.Legend.X = 3000;
chart.Legend.Area.ForegroundColor = Color.LightYellow;
chart.Legend.Shadow = true;
series1.XValues = “A1:A3”;
chart.CategoryAxis.TickLabels.RotationAngle = 45;
chart.CategoryAxis.TickLabels.Font.Size = 6;
chart.CategoryAxis.Title.Text = “”;
chart.SecondCategoryAxis.Title.Text = “”;
chart.SeriesAxis.Title.Text = “”;
chart.ValueAxis.Title.Text = “”;
wb.Save(“pre_merge_” + DateTime.Now.Ticks + “.xlsx”);
Workbook targetWorkbook = new Workbook();
targetWorkbook.Worksheets.Add(“targetTabName”);
Worksheet targetWorksheet = targetWorkbook.Worksheets[“targetTabName”];
targetWorkbook.Worksheets[“targetTabName”].Copy(sheet);
targetWorkbook.Save(“good_formatting_” + DateTime.Now.Ticks + “.xls”);
targetWorkbook.Save(“bad_formatting_” + DateTime.Now.Ticks + “.xlsx”);