K
Karthik N
Hi,
I need to allow the user to specify the table column width in the range
of 0.5cm to 0.1cm. When the value goes below 0.4, an exception "Value
out of range" is thrown.
I have appended the code snippet that I use. The exception is thrown
whenever the SetWidth method is called.
TIA
Karthik.
=======================================================
#region Move to start of document.
Object start = 0;
Object end = 0;
Word.Range rng = wDoc.Range(ref start, ref end);
#endregion
#region Add the table.
rng.InsertParagraphAfter();
rng.InsertParagraphAfter();
rng.SetRange(rng.End, rng.End);
rng.Tables.Add(wDoc.Paragraphs[2].Range, 1, 8,
ref missingObj, ref missingObj);
// Set variable to point to new table.
Word.Table tbl = wDoc.Tables[1];
#endregion
#region Corrective Action
tbl.Cell(1,1).Range.Text = "Sample Text 1";
tbl.Cell(1,2).Range.Text = "Sample Text 2";
tbl.Cell(1,3).Range.Text = "Sample Text 3";
tbl.Cell(1,4).Range.Text = "Sample Text 4";
tbl.Cell(1,5).Range.Text = "Sample Text 5";
tbl.Cell(1,6).Range.Text = "Sample Text 6";
tbl.Cell(1,7).Range.Text = "Sample Text 7";
tbl.Cell(1,8).Range.Text = "Sample Text 8";
tbl.Range.Font.Size = 1;
tbl.LeftPadding = 0.0F;
tbl.BottomPadding = 0.0F;
tbl.TopPadding = 0.0F;
tbl.RightPadding = 0.0F;
#endregion
#region Set the column widths.
for(int columnCounter=1; columnCounter <= tbl.Columns.Count;
columnCounter++)
{
if(columnCounter == 1)
{
tbl.Columns[columnCounter].SetWidth(wApp.CentimetersToPoints
(float.Parse(marginTB.Text)),Word.WdRulerStyle.wdAdjustNone);
}
else if((columnCounter != 1) && (columnCounter % 2 != 0))
{
tbl.Columns[columnCounter].SetWidth(wApp.CentimetersToPoints
(float.Parse(spaceTB.Text)),Word.WdRulerStyle.wdAdjustNone);
}
else
{
tbl.Columns[columnCounter].SetWidth(wApp.CentimetersToPoints
(float.Parse(widthTB.Text)),Word.WdRulerStyle.wdAdjustNone);
}
}
=======================================================
I need to allow the user to specify the table column width in the range
of 0.5cm to 0.1cm. When the value goes below 0.4, an exception "Value
out of range" is thrown.
I have appended the code snippet that I use. The exception is thrown
whenever the SetWidth method is called.
TIA
Karthik.
=======================================================
#region Move to start of document.
Object start = 0;
Object end = 0;
Word.Range rng = wDoc.Range(ref start, ref end);
#endregion
#region Add the table.
rng.InsertParagraphAfter();
rng.InsertParagraphAfter();
rng.SetRange(rng.End, rng.End);
rng.Tables.Add(wDoc.Paragraphs[2].Range, 1, 8,
ref missingObj, ref missingObj);
// Set variable to point to new table.
Word.Table tbl = wDoc.Tables[1];
#endregion
#region Corrective Action
tbl.Cell(1,1).Range.Text = "Sample Text 1";
tbl.Cell(1,2).Range.Text = "Sample Text 2";
tbl.Cell(1,3).Range.Text = "Sample Text 3";
tbl.Cell(1,4).Range.Text = "Sample Text 4";
tbl.Cell(1,5).Range.Text = "Sample Text 5";
tbl.Cell(1,6).Range.Text = "Sample Text 6";
tbl.Cell(1,7).Range.Text = "Sample Text 7";
tbl.Cell(1,8).Range.Text = "Sample Text 8";
tbl.Range.Font.Size = 1;
tbl.LeftPadding = 0.0F;
tbl.BottomPadding = 0.0F;
tbl.TopPadding = 0.0F;
tbl.RightPadding = 0.0F;
#endregion
#region Set the column widths.
for(int columnCounter=1; columnCounter <= tbl.Columns.Count;
columnCounter++)
{
if(columnCounter == 1)
{
tbl.Columns[columnCounter].SetWidth(wApp.CentimetersToPoints
(float.Parse(marginTB.Text)),Word.WdRulerStyle.wdAdjustNone);
}
else if((columnCounter != 1) && (columnCounter % 2 != 0))
{
tbl.Columns[columnCounter].SetWidth(wApp.CentimetersToPoints
(float.Parse(spaceTB.Text)),Word.WdRulerStyle.wdAdjustNone);
}
else
{
tbl.Columns[columnCounter].SetWidth(wApp.CentimetersToPoints
(float.Parse(widthTB.Text)),Word.WdRulerStyle.wdAdjustNone);
}
}
=======================================================