Suresh Behera

The Microsoft .Net Junkies

News

Blogroll

Reading

HOW TO : EXCEL/WORD @ VSTO 2005

Basic Workbook Tasks

Basic Worksheet Tasks

Securing Workbooks

Formatting

Working with Ranges

How to: Run Excel Calculations Programmatically

How to: Check Spelling in Worksheets

How to: Automatically Fill Ranges with Incrementally Changing Data

How to: Search for Text in Worksheet Ranges

Basic Document Tasks

Text and Objects in Documents

Searching and Replacing Text in Documents

Word Tables in Documents

Comments

Aleks said:

Do you know how to lock just one cell ?

# April 17, 2007 6:57 AM

Argyros said:

Interesting...

# April 21, 2007 3:35 PM

Myron said:

Cool.
# May 1, 2007 1:47 AM

alex# said:

Thomas en as déjà longuement parlé via un article qui dépeint grandement la technologie et qui reste

# August 22, 2007 8:31 AM

find leica cameras at http://leicacameracentral.info said:

The normal everyday person would think that investing the time to produce books on this topic of thought is a waste of money.

# November 28, 2007 6:47 PM

Jim Davis said:

I have purchased the book Visual Studio Tools for Office:Using C# with Excel, Word, Outlook, and InfoPath. From the book, I have been able to find example code for almost everything you can imagine, I am very impressed. However, one area that I am having problems with is - How can I create several tables, all the same number of rows and columns, and place each in a different location in a single document.

The data to be put into each cell is coming from a generic list, List<PageInformation>, using the following code. Can you tell me what is wrong with the way I am doing this, please:

int start = 0;

int end = 0

Word.Range tableLocation = null;

Word.Table table = null;

foreach(PageInformation pi in listInfo)

{

  tableLocation = Range(ref missing, ref missing);

  tableLocation.SetRange(start, end);

  table = Table(tableLocation, 5, 2, ref missing, ref missing);

  FormatTable(table);

  PopulateTable(pi, table);

  start += 300;

  end += 300;

}

private void FormatTable(Table table, PageInformation pi)

{

   table.Rows[1].Cells[1].Width = 125;

   table.Rows[1].Cells[1].Shading.BackgroundPatternColor = Word.WdColor.wdColorGray40;

   table.Rows[1].Cells[1].Range.Font.Color = WdColor.wdColorWhite;

   table.Rows[1].Cells[1].Range.Text = "Available to PAS User";

   table.Rows[1].Cells[1].Range.Font.Bold = 1;

   table.Rows[1].Cells[2].Width = 375;

   table.Rows[2].Cells[1].Width = 125;

   table.Rows[2].Cells[1].Shading.BackgroundPatternColor = Word.WdColor.wdColorGray40;

   table.Rows[2].Cells[1].Range.Font.Color = WdColor.wdColorWhite;

   table.Rows[2].Cells[1].Range.Text = "Available to PAT User";

   table.Rows[2].Cells[1].Range.Font.Bold = 1;

   table.Rows[2].Cells[2].Width = 375;

   table.Rows[3].Cells[1].Width = 125;

   table.Rows[3].Cells[1].Shading.BackgroundPatternColor = Word.WdColor.wdColorGray40;

   table.Rows[3].Cells[1].Range.Font.Color = WdColor.wdColorWhite;

   table.Rows[3].Cells[1].Range.Text = "Links to Page";

   table.Rows[3].Cells[1].Range.Font.Bold = 1;

   table.Rows[3].Cells[2].Width = 375;

   table.Rows[4].Cells[1].Width = 125;

   table.Rows[4].Cells[1].Shading.BackgroundPatternColor = Word.WdColor.wdColorGray40;

   table.Rows[4].Cells[1].Range.Font.Color = WdColor.wdColorWhite;

   table.Rows[4].Cells[1].Range.Text = "Function ID";

   table.Rows[4].Cells[1].Range.Font.Bold = 1;

   table.Rows[4].Cells[2].Width = 375;

   table.Rows[5].Cells[1].Width = 125;

   table.Rows[5].Cells[1].Shading.BackgroundPatternColor = Word.WdColor.wdColorGray40;

   table.Rows[5].Cells[1].Range.Font.Color = WdColor.wdColorWhite;

   table.Rows[5].Cells[1].Range.Text = "Visible If";

   table.Rows[5].Cells[1].Range.Font.Bold = 1;

   table.Rows[5].Cells[2].Width = 375;

}

private void PopulateTable(PageInformation pi, Table table)

{

   string sub = string.Empty;

   table.Rows[1].Cells[2].Range.Text = pi.AvailableToPasUsers == true ? "Yes" : "No";

   table.Rows[2].Cells[2].Range.Text = pi.AvailableToPatUsers == true ? "Yes" : "No";

   table.Rows[3].Cells[2].Range.Text = pi.LinksToPage;

   if (!string.IsNullOrEmpty(pi.PasRole))

   {

       sub = pi.PasRole.Substring(0, 1);

   }

   switch (sub)

   {

       case "r":

           table.Rows[4].Cells[2].Range.Text = pi.PasRole.Substring(1) + " " + READ;

           break;

       case "w":

           table.Rows[4].Cells[2].Range.Text = pi.PasRole.Substring(1) + " " + UPDATE;

           break;

       default:

           table.Rows[4].Cells[2].Range.Text = "None";

           break;

   }

   table.Rows[5].Cells[2].Range.Text = string.Empty;

}

# October 24, 2008 10:56 AM

Nerisha Bhajun-Visser said:

Thanks for the "Searching and Replacing Text" code, but I am looking for a way to search and replace paragraphs into a document.  Can you help me?

# August 14, 2009 4:56 AM

Ram said:

How can I check the styles that are applied to entire document.

# February 17, 2010 6:53 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)