473,394 Members | 2,090 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Excel Header and Footer Font from c#

Hello,

I am trying to set the MS Excel header and footer font
using automation from C#.

I can set the text using:

oPageSetup.LeftHeader = "Header Text";

but how do you set the Font size????
TIA,

John Hoffman
Nov 15 '05 #1
4 19595
I don't know how to do that, but I have a way to discover how excel does
things:
start excel, start recording a macro, look what the code does and then use
that code in your automation project. Simple but it works often.

Steven.
"John hoffman" <jo**********@excel-medical.com> wrote in message
news:05****************************@phx.gbl...
Hello,

I am trying to set the MS Excel header and footer font
using automation from C#.

I can set the text using:

oPageSetup.LeftHeader = "Header Text";

but how do you set the Font size????
TIA,

John Hoffman

Nov 15 '05 #2
Hi John,

Thank you for posting in MSDN managed newsgroup!

You can join the font type with the header size. I list sample code below:
'Code begin
ActiveSheet.PageSetup.LeftHeader = "&""Arial Unicode MS,Regular""Header Text"
'Code end

You can append the head text or foot text after "&""font type name""<header or foorter text>".

Furthermore, you can also try the method Steven suggested which will be very fast for you to create the macro code.

Please feel free to let me know if you have any further questions.

Does this answer your question? Thank you for using Microsoft NewsGroup!

Wei-Dong Xu
Microsoft Product Support Services
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
Nov 15 '05 #3
Hello Wei-Dong,

The sample code you sent:
ActiveSheet.PageSetup.LeftHeader = "&""Arial Unicode
MS,Regular""Header Text"

below is NOT valid C# syntax. (I believe it is the VB
macro code.)

I have tried
ActiveSheet.PageSetup.LeftHeader = "&" + "Arial Unicode
MS,Regular" + "Header Text";

but that just gives me the literal text in the header.

Any help would be appreciated.

TIA,

John Hoffman

-----Original Message-----
Hi John,

Thank you for posting in MSDN managed newsgroup!

You can join the font type with the header size. I list sample code below:'Code begin
ActiveSheet.PageSetup.LeftHeader = "&""Arial Unicode MS,Regular""Header Text"'Code end

You can append the head text or foot text after "&""font type name""<header or foorter text>".
Furthermore, you can also try the method Steven suggested which will be very fast for you to create the
macro code.
Please feel free to let me know if you have any further questions.
Does this answer your question? Thank you for using Microsoft NewsGroup!
Wei-Dong Xu
Microsoft Product Support Services
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

.

Nov 15 '05 #4
Hi John,

Thank you for replying!

In C#, the string ["&""Arial Unicode MS,Regular""Header Text"] will be thought invalid by the complier for so many quotation in this string. We can
use StringBuilder class to read this string and stringbuild class will transfer the string into one valid format which C# compiler prefers automatically.
I write the sample codes for you.

//Code begin
//the stringbuilder class is in the System.Text namespace
using System.Text;
...
try
{
Excel.Worksheet objWS;
StringBuilder str = new StringBuilder();

// the ["&""Arial Unicode MS,Regular""Header Text"] will be transferred into
// ["&\"Arial Unicode MS,Regular\"Header Text"] by stringBuilder internally
// which is valid in C#
str.Append(@"&""Arial Unicode MS,Regular""Header Text");

objWS = (Excel.Worksheet)this.ThisApplication.ActiveSheet;
objWS.PageSetup.LeftFooter = str.ToString();
}
catch(System.Exception ex)
{
MessageBox.Show(ex.Message);
}
//Code end

Furthermore, in your project, I'd suggest you can also use stringbuilder to create your footer and header string very easily with the Append
method.

In addition, in Visual Basic.Net and VBA, we can directly pass the ["&""Arial Unicode MS,Regular""Header Text"] string for the footer and header.

Please feel free to let me know if you have any further questions.

Does this answer your question? Thank you for using Microsoft NewsGroup!

Wei-Dong Xu
Microsoft Product Support Services
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
Nov 15 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: middletree | last post by:
I did a search in this forum, as well as at www.asp.faq.com, and MSDN, and would like to know how to use ASP to build a report and create an .xls file as a result. I've seen lots of tutorials...
2
by: creed1 | last post by:
I am currently working with an Active Server Page (ASP) that is set to redirect its output to Excel using Response.ContentType = "application/vnd.ms-excel". It works great, but I need to find a...
6
by: Kevin Humphreys | last post by:
Hi There, I am trying to export a recordset to an excel file using the Content Type below in the header. Response.ContentType = "application/vnd.ms-excel" Which works fine however the...
6
by: Elena | last post by:
I'm trying to export data to an Excel worksheet. I can export the data in the cell values perfectly. I need the code to change a header and footer for the worksheet, not for the columns. Is...
5
by: Elena | last post by:
I need the VB.NET code to change the header/footer of an Excel spread sheet, ASAP. I am doing it through a VB application. I can change the ranges/cell values using code, but I do not know how to...
6
by: McKirahan | last post by:
I an using ASP to read a database table and generate an HTML table which is save via FSO with a file extension of .xls which opens up in MS-Excel. I am inserting several lines of text into a cell...
3
by: sejal17 | last post by:
hello Can any one tell me how to read multiple worksheets from a single excel file.I have stored that excel in xml file.so i want to read that xml that has multiple worksheet.And i want to store...
3
by: sejal17 | last post by:
hello Can any one tell me how to read multiple worksheets from a single excel file.I have stored that excel in xml file.so i want to read that xml that has multiple worksheet.And i want to store...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.