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

Free Support Forum - aspose.com

RTF Excel

Hi,


How can I add a RTF to an excel document? Is this supported by Aspose?

I use Aspose.Cells.dll with Microsoft Visual Studio 2010

Thanks,

Hi,


Please see the following sample code on how to add rtf file as an Ole Object in Excel file for your requirements for your reference:
e.g
Sample code:

Workbook workbook = new Workbook(“e:\test2\Book1.xlsx”);
//Get the first worksheet.
Worksheet sheet = workbook.Worksheets[0];
//Define a string variable to store the image path.
string ImageUrl = @“e:\test\abc.jpg”;
//Get the picture into the streams.
FileStream fs = File.OpenRead(ImageUrl);
//Define a byte array.
byte[] imageData = new Byte[fs.Length];
//Obtain the picture into the array of bytes from streams.
fs.Read(imageData, 0, imageData.Length);
//Close the stream.
fs.Close();
//Get an rtf file path in a variable.
string path = @“e:\test2\test.rtf”;
//Get the file into the streams.
fs = File.OpenRead(path);
//Define an array of bytes.
byte[] objectData = new Byte[fs.Length];
//Store the file from streams.
fs.Read(objectData, 0, objectData.Length);
//Close the stream.
fs.Close();
sheet.OleObjects.Add(0, 0, 40, 40, imageData);
//Set embedded ole object data.
sheet.OleObjects[0].ObjectData = objectData;
sheet.OleObjects[0].FileFormatType = FileFormatType.Unknown;

sheet.OleObjects[0].ObjectSourceFullName = path;

//Save the excel file
workbook.Save(@“e:\test2\out1.xlsx”);

Hope, this helps a bit.

Thank you.

Sorry RTF = Rich Text Format

Hi,


Well, you may apply rich text formattings to the cells/ data using Aspose.Cells APIs, see the documents in the section “Working with Data Formatting”. The documents in the section denotes how to do (set/get) the formattings ( back/fore cell color, font/text color and other attributes, configurations, borders for the cells, etc.):
http://www.aspose.com/docs/display/cellsnet/Working+with+Data+Formatting
Hope, this helps a bit.

Thank you.

Sorry I’ll be more explicit. I have a RTF text in a database like this:


{\rtf1\fbidis\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fprq2\fcharset0 Arial;}{\f1\fnil\fcharset0 Segoe UI;}}
{\colortbl ;\red37\green37\blue37;}
\viewkind4\uc1\pard\ltrpar\sa200\sl276\slmult1\cf1\b\f0\fs21 In December 1930\b0 , Einstein visited \i America\i0 for the second time\cf0\f1\fs17\par
}

And I would like to put it in a Excel

In December 1930, Einstein visited America

At present, I can load a html code but I don’t know how to do the same with a RTF code.

Thanks,


Hi,


I am afraid, there is no other way and you have to manually do the formatting using Aspose.Cells APIs for your data in the cells, kindly refer to the documents in section which I mentioned in my previous reply. Please see the document especially on how to apply formatting to your desired characters in the cell for your reference:
http://www.aspose.com/docs/display/cellsnet/Formatting+Selected+Characters+in+a+Cell

Thank you.