Excel PIA C# - Format a Cell

  • Thread starter Thread starter Mike Strieder
  • Start date Start date
M

Mike Strieder

Hi,

thx for reading this entry and for your help

I select a cell in Excel (C#) and want to set the Text "ABC123". But in this
Cell the Text "123" should appear in Bold!
How can this work ???

Ciao Mike

ExcelApplication excel = new
ExcelApplication();excel.Workbooks.Open(@"c:\temp\xx.xls",Missing.Value,Miss
ing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Va
lue,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Mi
ssing.Value,Missing.Value); Worksheet wks = (Worksheet)excel.Sheets["test"];
Range r = wks.get_Range("A17", Missing.Value);
.... ????
 
Hi Mike,

Thanks for posting in the community. My name is Peter, and I will be
assisting you on this issue.

First of all, I would like to confirm my understanding of your issue.
From your description, I understand that you wants to automation the Excel
from C#, and need to set the value and format of a cell.
Have I fully understood you? If there is anything I misunderstood, please
feel free to let me know.

Here I write the code for you , you may have a try and let me know the
result.

using System;
using Excel=Microsoft.Office.Interop.Excel;
using System.Reflection;
class Class
{
[STAThread]
static void Main(string[] args)
{
Excel.Application exApp = new Excel.ApplicationClass();
exApp.Visible=true;

exApp.Workbooks.Open(@"c:\test.xls",Missing.Value,Missing.Value,Missing.Valu
e,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Miss
ing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Va
lue);
Excel.Worksheet wks = (Excel.Worksheet)exApp.Sheets["test"];
wks.get_Range("A17",Missing.Value ).set_Value(Missing.Value,"123456");
wks.get_Range("A17",Missing.Value ).Font.Bold=true;
}

Please Apply My Suggestion Above And Let Me Know If It Helps Resolve Your
Problem.

However, if the problem still persists, please help me collect more
information for further troubleshooting.


Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top