We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Add new line to Chart Title

I have the following code to set a Chart Title. I’d like for a portion to be one line and the remaining on another line.


chart.Title.Text = String.Format(“Chart Title{0}YTD 2015”, Environment.NewLine)

I’d like for it to render:

Chart Title
YTD 2015


But it renders

Chart Title_x000d_
YTD 2015


Is there a way to put a new line in format string when setting Chart titles?

Hi Travas,


Thank you for contacting Aspose support.

Please try using the newline metacharacter (\n) as follows. In case you still do not get the required results, please share your complete code along with supporting documents for further analysis.

C#

chart.Title.Text = “One Line \nSecond Line”;

When taking your recommendation to add “\n” does not have an affect. Title renders with \n included.


Currently language is VB.NET, not C# so I’m not sure if that matters.

Hi Travas,


First of all, please accept my apology for not noticing that you are using VB.NET as your coding language. You are correct, the string \n printed as it is in the title because VB.NET is not able to recognize it as a metacharacter. Please use the following equivalent statement for your requirement. I have also attached the VB module here in an archive that I used for my testing along with its result.

VB.NET

chart.Title.Text = "One line " & vbNewLine & “Another Line”
Setting worksheet.Charts(0).Title.Text = "line one" & vbCrLf & "another line"

Outputs:

line one_x000d_
another line


Hi Travas,


Inserting vbCrLf as new line feed is working equally correct on my side, however, I prefer to use vbNewLine instead of vbCrLf as it is a more descriptive variable that does the same thing.

Anyway, please create a zip archive of your complete project (including the dependencies) and post here for further investigation.

I still get the x0009 text output. Will try to recreate a solution to provide to you, but not sure when time will allow for that.

Hi,

Thanks for your posting and using Aspose.Cells.

Could you please try the latest version: Aspose.Cells
for .NET v8.6.0.4
because it is working fine. I have tested it with the following sample code and attached the source and output excel file for a reference.

C#
string filePath = @“F:\Shak-Data-RW\Downloads\source.xlsx”;

Workbook workbook = new Workbook(filePath);

Worksheet worksheet = workbook.Worksheets[0];

Chart chart = worksheet.Charts[0];
chart.Title.Text = “Some new \nline text”;

workbook.Save(“output.xlsx”);