Free Support Forum - aspose.com

Cells Doubt

Hi Amjad,

I am replacing Excel with Aspose Cells.

i have a problem:

Dim xlw As Aspose.Cells.Worksheet

Dim oFont as Aspose.Cells.Fonts = xlw.CreateFont

Basically the CreateFont functionality is for Excel, but nothing like that is available in Aspose.Kndly let me know what is to be done>??

Thanks,

nirmal

Hi nirmal,

Thanks for considering Aspose.

Do you want to apply fonts with their attributes (fontname, fontsize, italic, bold, color etc.) to the cells in the worksheet?

Please refer to the following code:

[VB]
'Create a Workbook.
Dim wbk As Aspose.Cells.Workbook =New Aspose.Cells.Workbook()
'Create a Worksheet and get the first sheet.
Dim worksheet As Aspose.Cells.Worksheet = wbk.Worksheets(0)
'Create a Cells object ot fetch all the cells.
Dim cells As Aspose.Cells.Cells = worksheet.Cells
'Merge some Cells into a single C6 Cell.
cells.Merge(5,2,2,3)
'Input data into C6 Cell.
worksheet.Cells(5,2).PutValue("This is my value")
'Create a Style object to fetch the Style of C6 Cell.
Dim style As Aspose.Cells.Style = worksheet.Cells(5,2).Style
'Create a Font object
Dim font As Aspose.Cells.Font = style.Font
'Set the name.
font.Name = "Times New Roman"
'Set the font size.
font.Size = 18
'Set the font color
font.Color = Color.Blue
'Bold the text
font.IsBold = True
'Make it italic
font.IsItalic = True
'Set the backgrond color of C6 Cell to yellow
style.ForegroundColor = Color.Yellow
style.Pattern = BackgroundType.Solid
'Apply the Style to C6 Cell.
cells(5,2).Style = style
'Save the Workbook.
wbk.Save("d:\test\applyfont2cells.xls")
[C#]
//Create a Workbook.
Aspose.Cells.Workbook wbk=new Aspose.Cells.Workbook();
//Create a Worksheet and get the first sheet.
Aspose.Cells.Worksheet worksheet = wbk.Worksheets[0];
//Create a Cells object ot fetch all the cells.
Aspose.Cells.Cells cells = worksheet.Cells;
//Merge some Cells into a single C6 Cell.
cells.Merge(5,2,2,3);
//Input data into C6 Cell.
worksheet.Cells[5,2].PutValue("This is my value");
//Create a Style object to fetch the Style of C6 Cell.
Aspose.Cells.Style style = worksheet.Cells[5,2].Style;
//Create a Font object
Aspose.Cells.Font font = style.Font;
//Set the name.
font.Name = "Times New Roman";
//Set the font size.
font.Size = 18;
//Set the font color
font.Color = Color.Blue;
//Bold the text
font.IsBold = true;
//Make it italic
font.IsItalic = true;
//Set the backgrond color of C6 Cell to yellow
style.ForegroundColor = Color.Yellow;
style.Pattern = BackgroundType.Solid;
//Apply the Style to C6 Cell.
cells[5,2].Style = style;
//Save the Workbook.
wbk.Save("d:\\test\\applyfont2cells.xls");
For further ref, please check:
http://www.aspose.com/wiki/default.aspx/Aspose.Cells/FontSetting.html
If you have further queries, feel free to contact us any time.
Thank you.

Hey Amjad,

You have given me the code to apply the style to a particular worksheet of a workbook.

But i want to apply the same for the entire work book.

My workbook object is xlw. I dont see the Cells function for the workbook mate wherein i can apply the style.

Please let me know about the same.

Thanks.

Nirmal

Hi Nirmal,

Thanks for considering Aspose.

Yes, you can do it. You may create a Style object and specify your required formattings and then use Workbook.DefaultStyle property to set it the style object.

May the following sample code helps you for your need.

[VB]
Dim wbk As Aspose.Cells.Workbook = New Aspose.Cells.Workbook()
Dim style As Aspose.Cells.Style = wbk.Styles(wbk.Styles.Add())
Dim font As Aspose.Cells.Font = style.Font
font.Name = "Times New Roman"
font.Size = 18
font.Color = Color.Blue
font.IsBold = True
font.IsItalic = True
style.ForegroundColor = Color.Yellow
style.Pattern = BackgroundType.Solid
wbk.DefaultStyle = style
wbk.Save("d:\test\applyfonts.xls")

[C#]
Aspose.Cells.Workbook wbk=new Aspose.Cells.Workbook();
Aspose.Cells.Style style = wbk.Styles[wbk.Styles.Add()];
Aspose.Cells.Font font = style.Font;
font.Name = "Times New Roman";
font.Size = 18;
font.Color = Color.Blue;
font.IsBold = true;
font.IsItalic = true;
style.ForegroundColor = Color.Yellow;
style.Pattern = BackgroundType.Solid;
wbk.DefaultStyle = style;
wbk.Save("d:\\test\\applyfonts.xls");
Thank you.