473,498 Members | 1,833 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

word automation using late binding

I developed this code which works fine in my current system which has office 2007, but when I run in word 2000 this doesn’t work. Can you please help me to code word automation using late binding. I want to create text, tables.


Word.Application WApp = new Word.Application(); // Open Microsoft Word application

object objMissing = System.Reflection.Missing.Value; // create the place holder object

Word.Document WDoc = WApp.Documents.Add(ref objMissing, ref objMissing, ref objMissing, ref objMissing); // create word document
Word.Paragraph WPara = WDoc.Paragraphs.Add(ref objMissing); // adding new paragraph

object start = 0; object end = 0;
int TableCount = 1;
String Str = "";

FormatStyle1(WPara);
WPara.Range.Text = "Batch Run Report:"; // Adding Text to paragraph
WPara.Range.InsertParagraphAfter(); // placing cursor on new paragraph

FormatStyle2(WPara);
WPara.Range.Text = "The following jobs were run on " + DateTime.Now.ToShortDateString() + " and the status is as follows:";
WPara.Range.InsertParagraphAfter();

FormatStyle1(WPara);
WPara.Range.Text = "Request Jobs:";
WPara.Range.InsertParagraphAfter();
CreateJobsTable(WDoc, WPara, TableCount);
Str = "set nocount on; " + " declare @dt_run datetime;" + " select @dt_run = dt_run from v$parm where id_record = 'datetime';" +
"select distinct id_job, isnull(dt_create, dt_run) dt_create into #temp from v$berr where dt_run >= @dt_run order by dt_create;" +
" alter table #temp alter column id_job char(10); " +
" insert into #temp select id_job, dt_create from batch_Job_Run_History where dt_run >= @dt_run order by dt_create; " +
" select upper(id_job) id_job, max(dt_create) dt_create into #temp1 from #temp where id_job like 'NEB%' or id_job like 'ARB%' group by id_job order by 2; " +
" select a.id_job, a.dt_create, b.cd_freq cd_freq from #temp1 a left outer join v$parm b on a.id_job = b.id_record where cd_freq = 'O' order by dt_create; ";
FillJobsTable(WDoc, TableCount, Str);
WPara.Range.InsertParagraphAfter();
TableCount++;

WPara.Range.Text = "Weekly Jobs:";
WPara.Range.InsertParagraphAfter();
CreateJobsTable(WDoc, WPara, TableCount);
Str = Str = "set nocount on; " + " declare @dt_run datetime;" + " select @dt_run = dt_run from v$parm where id_record = 'datetime';" +
"select distinct id_job, isnull(dt_create, dt_run) dt_create into #temp from v$berr where dt_run >= @dt_run order by dt_create;" +
" alter table #temp alter column id_job char(10); " +
" insert into #temp select id_job, dt_create from batch_Job_Run_History where dt_run >= @dt_run order by dt_create; " +
" select upper(id_job) id_job, max(dt_create) dt_create into #temp1 from #temp where id_job like 'NEB%' or id_job like 'ARB%' group by id_job order by 2; " +
" select a.id_job, a.dt_create, b.cd_freq cd_freq from #temp1 a left outer join v$parm b on a.id_job = b.id_record where cd_freq = 'W' order by dt_create; "; ;
FillJobsTable(WDoc, TableCount, Str);
WPara.Range.InsertParagraphAfter();
TableCount++;

WPara.Range.Text = "Quarterly Jobs:";
WPara.Range.InsertParagraphAfter();
CreateJobsTable(WDoc, WPara, TableCount);
Str = "set nocount on; " + " declare @dt_run datetime;" + " select @dt_run = dt_run from v$parm where id_record = 'datetime';" +
"select distinct id_job, isnull(dt_create, dt_run) dt_create into #temp from v$berr where dt_run >= @dt_run order by dt_create;" +
" alter table #temp alter column id_job char(10); " +
" insert into #temp select id_job, dt_create from batch_Job_Run_History where dt_run >= @dt_run order by dt_create; " +
" select upper(id_job) id_job, max(dt_create) dt_create into #temp1 from #temp where id_job like 'NEB%' or id_job like 'ARB%' group by id_job order by 2; " +
" select a.id_job, a.dt_create, b.cd_freq cd_freq from #temp1 a left outer join v$parm b on a.id_job = b.id_record where cd_freq = 'Q' order by dt_create; ";
FillJobsTable(WDoc, TableCount, Str);
WPara.Range.InsertParagraphAfter();
TableCount++;

WPara.Range.Text = "Bi Monthly Jobs:";
WPara.Range.InsertParagraphAfter();
CreateJobsTable(WDoc, WPara, TableCount);
Str = "set nocount on; " + " declare @dt_run datetime;" + " select @dt_run = dt_run from v$parm where id_record = 'datetime';" +
"select distinct id_job, isnull(dt_create, dt_run) dt_create into #temp from v$berr where dt_run >= @dt_run order by dt_create;" +
" alter table #temp alter column id_job char(10); " +
" insert into #temp select id_job, dt_create from batch_Job_Run_History where dt_run >= @dt_run order by dt_create; " +
" select upper(id_job) id_job, max(dt_create) dt_create into #temp1 from #temp where id_job like 'NEB%' or id_job like 'ARB%' group by id_job order by 2; " +
" select a.id_job, a.dt_create, b.cd_freq cd_freq from #temp1 a left outer join v$parm b on a.id_job = b.id_record where cd_freq = 'B' order by dt_create; ";
FillJobsTable(WDoc, TableCount, Str);
WPara.Range.InsertParagraphAfter();
TableCount++;

WPara.Range.Text = "Monthly Jobs:";
WPara.Range.InsertParagraphAfter();
CreateJobsTable(WDoc, WPara, TableCount);
Str = "set nocount on; " + " declare @dt_run datetime;" + " select @dt_run = dt_run from v$parm where id_record = 'datetime';" +
"select distinct id_job, isnull(dt_create, dt_run) dt_create into #temp from v$berr where dt_run >= @dt_run order by dt_create;" +
" alter table #temp alter column id_job char(10); " +
" insert into #temp select id_job, dt_create from batch_Job_Run_History where dt_run >= @dt_run order by dt_create; " +
" select upper(id_job) id_job, max(dt_create) dt_create into #temp1 from #temp where id_job like 'NEB%' or id_job like 'ARB%' group by id_job order by 2; " +
" select a.id_job, a.dt_create, b.cd_freq cd_freq from #temp1 a left outer join v$parm b on a.id_job = b.id_record where cd_freq = 'M' order by dt_create; ";
FillJobsTable(WDoc, TableCount, Str);
WPara.Range.InsertParagraphAfter();
TableCount++;

FormatStyle1(WPara);
WPara.Range.Text = "Daily Run Jobs:";
WPara.Range.InsertParagraphAfter();
CreateJobsTable(WDoc, WPara, TableCount);
Str = "set nocount on; " + " declare @dt_run datetime;" + " select @dt_run = dt_run from v$parm where id_record = 'datetime';" +
"select distinct id_job, isnull(dt_create, dt_run) dt_create into #temp from v$berr where dt_run >= @dt_run order by dt_create;" +
" alter table #temp alter column id_job char(10); " +
" insert into #temp select id_job, dt_create from batch_Job_Run_History where dt_run >= @dt_run order by dt_create; " +
" select upper(id_job) id_job, max(dt_create) dt_create into #temp1 from #temp where id_job like 'NEB%' or id_job like 'ARB%' group by id_job order by 2; " +
" select a.id_job, a.dt_create, b.cd_freq cd_freq from #temp1 a left outer join v$parm b on a.id_job = b.id_record where cd_freq = 'D' or cd_freq is null order by dt_create; ";

FillJobsTable(WDoc, TableCount, Str);
WPara.Range.InsertParagraphAfter();
TableCount++;

WPara.Range.Text = "Reports:";
WPara.Range.InsertParagraphAfter();
FormatStyle2(WPara);
WPara.Range.Text = "The following reports were run successfully and the PDF files have been generated.";
WPara.Range.InsertParagraphAfter();
CreateReportsTable(WDoc, WPara, TableCount);
WPara.Range.InsertParagraphAfter();
TableCount++;

FormatStyle1(WPara);
WPara.Range.Text = "Forms:";
WPara.Range.InsertParagraphAfter();
CreateFormsTable(WDoc, WPara, TableCount);
WPara.Range.InsertParagraphAfter();
TableCount++;

WPara.Range.Text = "Check Details:";
WPara.Range.InsertParagraphAfter();
CreateCheckDetailsTable(WDoc, WPara, TableCount);
TableCount++;

WPara.Range.Text = "EFT and FTP Details:";
WPara.Range.InsertParagraphAfter();

FormatStyle2(WPara);
WPara.Range.Text = "EFT disbursement file, the Pay issue file and check file have been generated and the FTP's were sent to bank of america and commercial mail.";
WPara.Range.InsertParagraphAfter();

FormatStyle1(WPara);
WPara.Range.Text = "Comments:";
WPara.Range.InsertParagraphAfter();

FormatStyle2(WPara);
WPara.Range.Text = "Batch was successful.";
WPara.Range.InsertParagraphAfter();

WPara.Range.Text = "Batch Start Time: " + DateTime.Now.ToString("M") + ", 6:00 PM";
WPara.Range.InsertParagraphAfter();

WPara.Range.Text = "Batch End Time: " + DateTime.Now.ToString("M") + ", " + DateTime.Now.ToLongTimeString();
WPara.Range.InsertParagraphAfter();

ExitDoc(WDoc, WApp, objMissing);

}

public static void CreateJobsTable(Word.Document WDoc, Word.Paragraph WPara, int TableCount)
{

object objDefaultBehaviorWord8 = Word.WdDefaultTableBehavior.wdWord8TableBehavior;
object objAutoFitFixed = Word.WdAutoFitBehavior.wdAutoFitFixed;

WPara.Range.Tables.Add(WPara.Range, 1, 3, ref objDefaultBehaviorWord8, ref objAutoFitFixed);

Word.Table Tbl = WDoc.Tables[TableCount];

Tbl.Range.Font.Size = 10;
Tbl.Range.Font.Name = "Times New Roman";
Tbl.Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft;
Tbl.Range.Font.Underline = Word.WdUnderline.wdUnderlineNone;

Object style = "Table Grid 1";
Tbl.set_Style(ref style);
Tbl.Spacing = 1.1f; // table within table
Tbl.ApplyStyleFirstColumn = false;
Tbl.ApplyStyleLastColumn = false;
Tbl.ApplyStyleLastRow = false;

// Insert header text and format the columns.
Tbl.Columns[1].SetWidth(30, Word.WdRulerStyle.wdAdjustSameWidth);
Tbl.Cell(1, 1).Shading.BackgroundPatternColor = Microsoft.Office.Interop.Word.WdColor.wdColorGray4 0;
Tbl.Cell(1, 1).Range.Text = "No.";

Word.Range rngCell;
rngCell = Tbl.Cell(1, 2).Range;
Tbl.Columns[2].SetWidth(160, Word.WdRulerStyle.wdAdjustSameWidth);
Tbl.Cell(1, 2).Shading.BackgroundPatternColor = Microsoft.Office.Interop.Word.WdColor.wdColorGray4 0;
rngCell.Text = "Job Name";

rngCell = Tbl.Cell(1, 3).Range;
Tbl.Columns[3].SetWidth(70, Word.WdRulerStyle.wdAdjustSameWidth);
Tbl.Cell(1, 3).Shading.BackgroundPatternColor = Microsoft.Office.Interop.Word.WdColor.wdColorGray4 0;
rngCell.Text = "Job Status";
}

public static void FillJobsTable(Word.Document WDoc, int TableCount, string Str)
{
Word.Table Tbl = WDoc.Tables[TableCount];
Object beforeRow = Type.Missing;

SqlConnection cnn;
SqlCommand cmd;
SqlDataReader dr = null;
System.IO.StringWriter sw = new System.IO.StringWriter();

cnn = new SqlConnection("Data Source=sqlp1; Database=PROD1;" + "Integrated Security=true");
cnn.Open();

cmd = new SqlCommand(Str, cnn);
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection) ;

if (dr.HasRows)
{
int RNow = 2;
int j = 1;

while (dr.Read())
{
Tbl.Rows.Add(ref beforeRow);
Tbl.Cell(RNow, 1).Shading.BackgroundPatternColor = Microsoft.Office.Interop.Word.WdColor.wdColorWhite ;
Tbl.Cell(RNow, 2).Shading.BackgroundPatternColor = Microsoft.Office.Interop.Word.WdColor.wdColorWhite ;
Tbl.Cell(RNow, 3).Shading.BackgroundPatternColor = Microsoft.Office.Interop.Word.WdColor.wdColorWhite ;
Tbl.Cell(RNow, 1).Range.Text = "" + j + "";
Tbl.Cell(RNow, 2).Range.Text = dr[0].ToString();
Tbl.Cell(RNow, 3).Range.Text = "Successful";
TableCellFormatting(Tbl, RNow);
RNow++;
j = j + 1;
}

if (dr != null)
{
dr.Close();
dr.Dispose();
}

}

else
{
dr.Close();
dr.Dispose();
cnn.Close();
}

}

public static void FormatStyle1(Word.Paragraph WPara)
{
WPara.Range.Font.Name = "Times New Roman";
WPara.Range.Font.Size = 10;
WPara.Range.Font.Bold = 1;
WPara.Range.Font.Underline = Word.WdUnderline.wdUnderlineSingle;
}

public static void FormatStyle2(Word.Paragraph WPara)
{
WPara.Range.Font.Name = "Times New Roman";
WPara.Range.Font.Size = 11;
WPara.Range.Font.Bold = 0;
WPara.Range.Font.Underline = Word.WdUnderline.wdUnderlineNone;
}

public static void TableCellFormatting(Word.Table Tbl, int RNow)
{
Tbl.Cell(RNow, 1).Range.Font.Bold = 0;
Tbl.Cell(RNow, 2).Range.Font.Bold = 0;
Tbl.Cell(RNow, 3).Range.Font.Bold = 0;
}

public static void TableCellFormatting2(Word.Table Tbl, int RNow)
{
Tbl.Cell(RNow, 1).Range.Font.Bold = 0;
Tbl.Cell(RNow, 1).Range.Font.Bold = 0;
Tbl.Cell(RNow, 1).Range.Font.Bold = 0;
}

public static void CreateReportsTable(Word.Document WDoc, Word.Paragraph WPara, int TableCount)
{

object objDefaultBehaviorWord8 = Word.WdDefaultTableBehavior.wdWord8TableBehavior;
object objAutoFitFixed = Word.WdAutoFitBehavior.wdAutoFitFixed;

WPara.Range.Tables.Add(WPara.Range, 1, 5, ref objDefaultBehaviorWord8, ref objAutoFitFixed);

Word.Table Tbl = WDoc.Tables[TableCount];

Tbl.Range.Font.Size = 10;
Tbl.Range.Font.Name = "Times New Roman";
Tbl.Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft;
Tbl.Range.Font.Underline = Word.WdUnderline.wdUnderlineNone;

Object style = "Table Grid 1";
Tbl.set_Style(ref style);
Tbl.Spacing = 1.1f;
Tbl.ApplyStyleFirstColumn = false;
Tbl.ApplyStyleLastColumn = false;
Tbl.ApplyStyleLastRow = false;

Tbl.Columns[1].SetWidth(70, Word.WdRulerStyle.wdAdjustSameWidth);
Tbl.Cell(1, 1).Shading.BackgroundPatternColor = Microsoft.Office.Interop.Word.WdColor.wdColorGray4 0;
Tbl.Cell(1, 1).Range.Text = "Report Name";
Tbl.Cell(1, 1).Range.Font.Bold = 1;

Object beforeRow = Type.Missing;
int RNow = 2;

SqlConnection cnn;
SqlCommand cmd;
SqlDataReader dr = null;
System.IO.StringWriter sw = new System.IO.StringWriter();

string strSQL = "set Nocount on; " + "declare @dt_run datetime; " + " select @dt_run = dt_run from prod1..v$parm where id_record = 'datetime';" +
" select substring(name, (charindex('_R', name, 1)+1),(len(name)- charindex('_R', name, 1))) as RName into #temp1 from argent..ajs_job where charindex('_R', name, 1) > 0 and (name not like '%REST_%') and (name not like '%READONLY_%'); " +
" update #temp1 set RName = 'RDB15' where RName like '%RDB15_%'; " +
" delete from #temp1 where RName in ('RR3040_RECON_FILE_REQUEST', 'REPORTS_ARCHIVE', 'REPORTS_ARCHIVE', 'REPORT'); " +
" select id_record from prod1..Tbl_Batch_Report_Print_Summary where DT_Report = @dt_run " +
" union " +
" select distinct id_job from prod1..v$berr where dt_run = @dt_run and id_job like 'R%' " +
" union " +
" select distinct RName from #temp1 " +
" union " +
" select substring(name, (charindex('_N', name, 1)+1),(len(name)- charindex('_N', name, 1))) as RName from argent..ajs_job where charindex('_N', name, 1) > 0 and name like '%_NPAGE%'" +
" union " +
" select substring(name, (charindex('_S', name, 1)+1),(len(name)- charindex('_S', name, 1))) as RName from argent..ajs_job where charindex('_S', name, 1) > 0 and name like '%_SDU%' and name not like '%SDU_OCSE%' and name not like '%SDUP_BACKUP%' and name not like '%SDU_IN%';";

cnn = new SqlConnection("Data Source=sqlp1; Database=ARGENT;" + "Integrated Security=true");
cnn.Open();

cmd = new SqlCommand(strSQL, cnn);
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection) ;

int j = 1;
Tbl.Rows.Add(ref beforeRow);

while (dr.Read())
{
Tbl.Cell(RNow, j).Range.Font.Bold = 0;
Tbl.Cell(RNow, j).Shading.BackgroundPatternColor = Microsoft.Office.Interop.Word.WdColor.wdColorWhite ;
Tbl.Cell(RNow, j).SetWidth(70, Microsoft.Office.Interop.Word.WdRulerStyle.wdAdjus tSameWidth);
Tbl.Cell(RNow, j).Range.Text = dr[0].ToString();
j++;

if (j>5)
{
j = 1;
RNow++;
Tbl.Rows.Add(ref beforeRow);
}

}

Tbl.Cell(1, 1).Merge(Tbl.Cell(1, 5));
Tbl.Cell(1, 1).SetWidth(350, Microsoft.Office.Interop.Word.WdRulerStyle.wdAdjus tSameWidth);
Tbl.Cell(1, 1).Shading.BackgroundPatternColor = Microsoft.Office.Interop.Word.WdColor.wdColorGray4 0;
Tbl.Cell(1, 1).Range.Text = "Report Name";
Tbl.Cell(1, 1).Range.Font.Bold = 1;

if (dr != null)
{
dr.Close();
dr.Dispose();
}

strSQL = "";
cnn.Close();

}

public static void CreateFormsTable(Word.Document WDoc, Word.Paragraph WPara, int TableCount)
{

object objDefaultBehaviorWord8 = Word.WdDefaultTableBehavior.wdWord8TableBehavior;
object objAutoFitFixed = Word.WdAutoFitBehavior.wdAutoFitFixed;

WPara.Range.Tables.Add(WPara.Range, 1, 2, ref objDefaultBehaviorWord8, ref objAutoFitFixed);

Word.Table Tbl = WDoc.Tables[TableCount];

Tbl.Range.Font.Size = 10;
Tbl.Range.Font.Name = "Times New Roman";
Tbl.Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft;
Tbl.Range.Font.Underline = Word.WdUnderline.wdUnderlineNone;

Object style = "Table Grid 1";
Tbl.set_Style(ref style);
Tbl.Spacing = 1.1f;
Tbl.ApplyStyleFirstColumn = false;
Tbl.ApplyStyleLastColumn = false;
Tbl.ApplyStyleLastRow = false;
Tbl.Columns[1].SetWidth(70, Word.WdRulerStyle.wdAdjustSameWidth);
Tbl.Cell(1, 1).Shading.BackgroundPatternColor = Microsoft.Office.Interop.Word.WdColor.wdColorGray4 0;
Tbl.Cell(1, 1).Range.Text = "Form Name";
Tbl.Columns[2].SetWidth(50, Word.WdRulerStyle.wdAdjustSameWidth);
Tbl.Cell(1, 2).Shading.BackgroundPatternColor = Microsoft.Office.Interop.Word.WdColor.wdColorGray4 0;
Tbl.Cell(1, 2).Range.Text = "Count";

/* filling the form tables*/
Object beforeRow = Type.Missing;
int RNow = 2;

SqlConnection cnn;
SqlCommand cmd;
SqlDataReader dr = null;
System.IO.StringWriter sw = new System.IO.StringWriter();

string strSQL = "set Nocount on;" +
"Declare @RUNDATE datetime; Select @RUNDATE = Convert(Char(10), Dt_Run, 121) + ' 16:00:00.000' From V$PARM Where Id_Record = 'DATETIME';" +
"select ID_FORM, count(*) Count_each into #temp1 from vfrrq where DT_CREATE_FMRQ >= @RUNDATE and cd_mode_print='b' group by id_form order by id_form;" +
"insert into #temp1 select 'Total', count(*) from vfrrq where DT_CREATE_FMRQ > @RUNDATE and cd_mode_print='B';" +
"select * from #temp1 order by 1;";

cnn = new SqlConnection("Data Source=sqlp1; Database=PROD1;" + "Integrated Security=true");
cnn.Open();

cmd = new SqlCommand(strSQL, cnn);
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection) ;

while (dr.Read())
{
Tbl.Rows.Add(ref beforeRow);
Tbl.Cell(RNow, 1).Range.Font.Bold = 0;
Tbl.Cell(RNow, 1).Shading.BackgroundPatternColor = Microsoft.Office.Interop.Word.WdColor.wdColorWhite ;
Tbl.Cell(RNow, 1).Range.Text = dr[0].ToString();
Tbl.Cell(RNow, 2).Range.Font.Bold = 0;
Tbl.Cell(RNow, 2).Shading.BackgroundPatternColor = Microsoft.Office.Interop.Word.WdColor.wdColorWhite ;
Tbl.Cell(RNow, 2).Range.Text = dr[1].ToString();
RNow++;
}

RNow = RNow - 1;
Tbl.Cell(RNow, 1).Range.Font.Bold = 1;

if (dr != null)
{
dr.Close();
dr.Dispose();
}

strSQL = "";
cnn.Close();

}

public static void CreateCheckDetailsTable(Word.Document WDoc, Word.Paragraph WPara, int TableCount)
{

object objDefaultBehaviorWord8 = Word.WdDefaultTableBehavior.wdWord8TableBehavior;
object objAutoFitFixed = Word.WdAutoFitBehavior.wdAutoFitFixed;

WPara.Range.Tables.Add(WPara.Range, 1, 5, ref objDefaultBehaviorWord8, ref objAutoFitFixed);

Word.Table Tbl = WDoc.Tables[TableCount];

Tbl.Range.Font.Size = 10;
Tbl.Range.Font.Name = "Times New Roman";
Tbl.Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft;
Tbl.Range.Font.Underline = Word.WdUnderline.wdUnderlineNone;

Object style = "Table Grid 1";
Tbl.set_Style(ref style);
Tbl.Spacing = 1.1f;
Tbl.ApplyStyleFirstColumn = false;
Tbl.ApplyStyleLastColumn = false;
Tbl.ApplyStyleLastRow = false;

Tbl.Columns[1].SetWidth(80, Word.WdRulerStyle.wdAdjustSameWidth);
Tbl.Cell(1, 1).Shading.BackgroundPatternColor = Microsoft.Office.Interop.Word.WdColor.wdColorGray4 0;
Tbl.Cell(1, 1).Range.Text = "CASE TYPE";


Tbl.Columns[2].SetWidth(92, Word.WdRulerStyle.wdAdjustSameWidth);
Tbl.Cell(1, 2).Shading.BackgroundPatternColor = Microsoft.Office.Interop.Word.WdColor.wdColorGray4 0;
Tbl.Cell(1, 2).Range.Text = "STARTING CHECK NUMBER";

Tbl.Columns[3].SetWidth(98, Word.WdRulerStyle.wdAdjustSameWidth);
Tbl.Cell(1, 3).Shading.BackgroundPatternColor = Microsoft.Office.Interop.Word.WdColor.wdColorGray4 0;
Tbl.Cell(1, 3).Range.Text = "ENDING CHECK NUMBER";

Tbl.Columns[4].SetWidth(88, Word.WdRulerStyle.wdAdjustSameWidth);
Tbl.Cell(1, 4).Shading.BackgroundPatternColor = Microsoft.Office.Interop.Word.WdColor.wdColorGray4 0;
Tbl.Cell(1, 4).Range.Text = "TOTAL NO. OF CHECKS";

Tbl.Columns[5].SetWidth(88, Word.WdRulerStyle.wdAdjustSameWidth);
Tbl.Cell(1, 5).Shading.BackgroundPatternColor = Microsoft.Office.Interop.Word.WdColor.wdColorGray4 0;
Tbl.Cell(1, 5).Range.Text = "TOTAL AMOUNT DISBURSED";

Object beforeRow = Type.Missing;
int RNow = 2;

SqlConnection cnn;
SqlCommand cmd;
SqlDataReader dr = null;
System.IO.StringWriter sw = new System.IO.StringWriter();

string strSQL = "exec Select_RDB01A_Header";

cnn = new SqlConnection("Data Source=OCSECMDEV; Database=CMSTAGING1;" + "Integrated Security=true");
cnn.Open();

cmd = new SqlCommand(strSQL, cnn);
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection) ;

while (dr.Read())
{
Tbl.Rows.Add(ref beforeRow);
Tbl.Cell(RNow, 1).Range.Font.Bold = 0;
Tbl.Cell(RNow, 1).Shading.BackgroundPatternColor = Microsoft.Office.Interop.Word.WdColor.wdColorWhite ;
Tbl.Cell(RNow, 1).Range.Text = "IVD";
Tbl.Cell(RNow, 2).Range.Font.Bold = 0;
Tbl.Cell(RNow, 2).Shading.BackgroundPatternColor = Microsoft.Office.Interop.Word.WdColor.wdColorWhite ;
Tbl.Cell(RNow, 2).Range.Text = dr[1].ToString();
Tbl.Cell(RNow, 3).Range.Font.Bold = 0;
Tbl.Cell(RNow, 3).Shading.BackgroundPatternColor = Microsoft.Office.Interop.Word.WdColor.wdColorWhite ;
Tbl.Cell(RNow, 3).Range.Text = dr[2].ToString();
Tbl.Cell(RNow, 4).Range.Font.Bold = 0;
Tbl.Cell(RNow, 4).Shading.BackgroundPatternColor = Microsoft.Office.Interop.Word.WdColor.wdColorWhite ;
Tbl.Cell(RNow, 4).Range.Text = dr[3].ToString();
Tbl.Cell(RNow, 5).Range.Font.Bold = 0;
Tbl.Cell(RNow, 5).Shading.BackgroundPatternColor = Microsoft.Office.Interop.Word.WdColor.wdColorWhite ;
Tbl.Cell(RNow, 5).Range.Text = dr[4].ToString();
RNow++;

Tbl.Rows.Add(ref beforeRow);
Tbl.Cell(RNow, 1).Range.Font.Bold = 0;
Tbl.Cell(RNow, 1).Range.Text = "MONITORING";
Tbl.Cell(RNow, 2).Range.Font.Bold = 0;
Tbl.Cell(RNow, 2).Range.Text = dr[5].ToString();
Tbl.Cell(RNow, 3).Range.Font.Bold = 0;
Tbl.Cell(RNow, 3).Range.Text = dr[6].ToString();
Tbl.Cell(RNow, 4).Range.Font.Bold = 0;
Tbl.Cell(RNow, 4).Range.Text = dr[7].ToString();
Tbl.Cell(RNow, 5).Range.Font.Bold = 0;
Tbl.Cell(RNow, 5).Range.Text = dr[8].ToString();
WPara.Range.InsertParagraphAfter();
RNow++;

Tbl.Rows.Add(ref beforeRow);

Tbl.Cell(RNow, 1).Merge(Tbl.Cell(RNow, 2));
Tbl.Cell(RNow, 1).Borders.Enable = 0;

Tbl.Cell(RNow, 2).Range.Font.Bold = 1;
Tbl.Cell(RNow, 2).Range.Text = "GRAND TOTAL";
Tbl.Cell(RNow, 3).Range.Font.Bold = 0;
Tbl.Cell(RNow, 3).Range.Text = dr[11].ToString();
Tbl.Cell(RNow, 4).Range.Font.Bold = 0;
Tbl.Cell(RNow, 4).Range.Text = dr[12].ToString();
}

if (dr != null)
{
dr.Close();
dr.Dispose();
}

strSQL = "";
cnn.Close();

}

public static void ExitDoc(Word.Document WDoc, Word.Application WApp, object objMissing)
{
object FileName = "c:\\Daily Batch Run Report " + (DateTime.Now.ToShortDateString()).Replace("/", "-") + ".docx";

WDoc.SaveAs(ref FileName,
ref objMissing, ref objMissing,
ref objMissing, ref objMissing,
ref objMissing, ref objMissing,
ref objMissing, ref objMissing,
ref objMissing, ref objMissing,
ref objMissing, ref objMissing,
ref objMissing, ref objMissing,
ref objMissing);

((Word._Document)WDoc).Close(ref objMissing, ref objMissing, ref objMissing);
((Word._Application)WApp).Quit(ref objMissing, ref objMissing, ref objMissing);

}
Sep 29 '10 #1
0 1739

Sign in to post your reply or Sign up for a free account.

Similar topics

2
6627
by: Mystery Man | last post by:
We are developing a C# application that has many interfaces to the Microsoft suite (eg Word, Excel, Outlook, Powerpoint, etc). We need to support Office 97, 2000, 2002 and any future versions. ...
0
1454
by: Tommy | last post by:
Hello! Does anybody know how to insert text into bookmarks in Word using late binding? If I use early binding everything works fine. What I want to implement is somthing like this: for (int i...
8
1525
by: scorpion53061 | last post by:
I am sorry for this but I am not getting an answer elsewhere so I thought I would try here. It seems the safer way to go prior to deployment is to change my early binding to late binding to...
4
1740
by: Steven | last post by:
Hi, I have a database table field to store the form name, I want to create the particular windows form by using the value that read from that DB field. For examples, the table field has a value...
1
2899
by: bluestar | last post by:
hello i am trying to develope an application for word automation.i need to insert header and footer to the document. i found an exampke in msdn and used it in my application.it works well;but...
0
1362
by: Lauren Quantrell | last post by:
I'm using the code below to export an Access 2K contact to Outlook 2K. It works fine as long as Outlook is running, however, I get an error is Outlook is closed. The error is: Method 'Save' of...
1
2753
by: =?Utf-8?B?U3RldmUgUmFuZGFsbA==?= | last post by:
Hi, Does anyone have any code samples (or links to) for sending an email message via outlook using late binding? Many thanks.
0
1061
by: =?Utf-8?B?U3RldmUgUmFuZGFsbA==?= | last post by:
Hi, Does anyone have any code samples in C# (or links to) for sending an email message via outlook using late binding? Many thanks.
0
781
by: venkatesh123 | last post by:
How to specify the formatting styles of the word document in programming(in .net)...can anyone suggest the solution...
5
1812
Xx r3negade
by: Xx r3negade | last post by:
I have a function, which reads input from a file and appends each line of the file to an STL object. I want to use this function with both lists and vectors. Since both of these objects have the...
0
7125
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7167
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,...
1
6890
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
4915
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4593
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3095
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3085
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1423
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
292
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.