Hi,
I have following problem. I add TextBox to chart:
TextBox footer = chart.Shapes.AddTextBoxInChart(4000 - height, 1010, height, 2000);
footer.Text = chartConfig.footer.text;
footer.Characters(0, footer.Text.Length).Font.IsBold = true;
footer.Characters(0, footer.Text.Length).Font.Color = Color.Red;
footer.Characters(0, footer.Text.Length).Font.Size = 20;
footer.TextHorizontalAlignment = TextAlignmentType.Center;
footer.Fill.Type = FillType.None;
footer.HasLine = false;
//footer.TextFrame.TopMarginPt=0.0;
I would like to change property selected in attached file(TopMargin = 0 ).
Best Regards,
Piotr
Hi,
Thanks for your posting and using Aspose.Cells for .NET
I think, TextBox.TextFrame sub-properties will fulfill your needs. These are the following.
Changing them will change the textbox internal margin.
- TextBox.TextFrame.BottomMarginPt
- TextBox.TextFrame.TopMarginPt
- TextBox.TextFrame.LeftMarginPt
- TextBox.TextFrame.RightMarginPt
These properties return or set the internal margins in
Units of Points. However, Ms-Excel shows them in
Units of Inches/Centimeters. So you will have to map them accordingly.
Let us know if you face any issue.
Hi,
Thanks for response. Could you explain me where I make mistake? Is it correct mapping? 0 Units of Points == 0 Units of Centimeters. I think I am wrong because when I check the value in generated document the top margin value is 0,09 cm. I know that it is small difference but I have to set it to be zero.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Aspose.Cells;
using Aspose.Cells.Drawing;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Workbook workbook = new Workbook();
int sheetIndex = workbook.Worksheets.Add();
Worksheet worksheet = workbook.Worksheets[sheetIndex];
worksheet.Cells["A1"].PutValue(50);
worksheet.Cells["A2"].PutValue(100);
worksheet.Cells["A3"].PutValue(150);
worksheet.Cells["B1"].PutValue(4);
worksheet.Cells["B2"].PutValue(20);
worksheet.Cells["B3"].PutValue(50);
int chartIndex = worksheet.Charts.Add(Aspose.Cells.Charts.ChartType.Pyramid, 5, 0, 30, 10);
Aspose.Cells.Charts.Chart chart = worksheet.Charts[chartIndex];
chart.NSeries.Add("A1:B3", true);
TextBox footer = chart.Shapes.AddTextBoxInChart(3000, 1010, 1000, 2000);
footer.Text = "text";
footer.Characters(0, footer.Text.Length).Font.IsBold = true;
footer.Characters(0, footer.Text.Length).Font.Size = 15;
footer.TextHorizontalAlignment = TextAlignmentType.Center;
footer.Fill.Type = FillType.None;
footer.HasLine = false;
footer.TextFrame.TopMarginPt=0.0;
workbook.Save("C:\\bookss.xls");
}
}
}
Best Regards
Piotr
Hi,
Thanks for your posting and providing your sample code.
I have looked into your issue and found that if you set the AutoSize and IsAutoMargin properties to false, then whatever value you will assign to Top, Bottom, Right, Left margin properties, it will have effect.
For example, I have assigned 0 to margin properties and the corresponding values in Excel file also gets changed to 0.
Please see the following sample code. I have attached the output xls file and screenshot illustrating their working for your reference.
Please download and use the latest version:
Aspose.Cells
for .NET v7.3.2.3
C#
Workbook workbook = new Workbook();
int sheetIndex = 0;
Worksheet worksheet = workbook.Worksheets[sheetIndex];
worksheet.Cells[“A1”].PutValue(50);
worksheet.Cells[“A2”].PutValue(100);
worksheet.Cells[“A3”].PutValue(150);
worksheet.Cells[“B1”].PutValue(4);
worksheet.Cells[“B2”].PutValue(20);
worksheet.Cells[“B3”].PutValue(50);
int chartIndex = worksheet.Charts.Add(Aspose.Cells.Charts.ChartType.Pyramid, 5, 0, 30, 10);
Aspose.Cells.Charts.Chart chart = worksheet.Charts[chartIndex];
chart.NSeries.Add(“A1:B3”, true);
Aspose.Cells.Drawing.TextBox footer = chart.Shapes.AddTextBoxInChart(3000, 1010, 1000, 2000);
footer.Text = “text”;
footer.Characters(0, footer.Text.Length).Font.IsBold = true;
footer.Characters(0, footer.Text.Length).Font.Size = 15;
footer.TextHorizontalAlignment = TextAlignmentType.Center;
footer.Fill.Type = FillType.None;
footer.HasLine = false;
//Set the AutoSize and IsAutoMargin property false
//then if you will assign 0 to margins, it will work fine
footer.TextFrame.AutoSize = false;
footer.TextFrame.IsAutoMargin = false;
footer.TextFrame.TopMarginPt = 0;
footer.TextFrame.BottomMarginPt = 0;
footer.TextFrame.LeftMarginPt = 0;
footer.TextFrame.RightMarginPt = 0;
workbook.Save(“output.xls”);
Screenshot:
Hi,
Thanks for great solution!
Best Regards
Piotr
Hi,
Thanks for your posting and using Aspose.
You are welcome and it’s good to know that above sample code was helpful for you to resolve this issue.
Let us know if you face any other issue relating to Aspose.Cells, we will be glad to help you asap.