# Transferring MS Excel Fonts to a Textbox

#### Milhous

##### New member
Simple problem:
I want to read the text (and font) of an excel cell, and then write it (with the same font) to a windows application textbox.

I can open the excel file, and read the text and font:
Dim fontE As Microsoft.Office.Interop.Excel.Font
Dim textE As string
textE = thefile.theworksheet.Cells(1,1).value
fontE = thefile.theworksheet.Cells(1,1).font

I can put the text in the textbox
textbox1.text = textE
But how do I transfer the excel font information to the textbox.

I suppose really all I need is fontname and fontsize. Thanks for your help, nothing I have tried has worked.

~Milhous~

#### Arg81

##### Well-known member
I might be barking up the wrong tree, but wouldn't you need to get the font name and the font size instead of just "font" ?

Not sure if this would work, but to adjust a textbox / label font you need to create a new font first.

Maybe try;

VB.NET:
``````Dim fontE As Microsoft.Office.Interop.Excel.Font
Dim textE As string
textE = thefile.theworksheet.Cells(1,1).value
fontE = thefile.theworksheet.Cells(1,1).font

Dim xFont as new font (fontE)
textbox1.font = xFont``````

Not quite sure whether that would work, but using the "new font" is where you set the font settings, i.e Dim xFont as new font ("Aerial", 14, FontStyle.Bold)

All the best, hopefully that can at least point you in the right direction.

Replies
0
Views
838
Replies
1
Views
2K
Replies
2
Views
379
Replies
4
Views
560
Replies
45
Views
3K