how do i differentiate between the two tables
-
I am trying to create 2 separate tables and print them in word, however I end up with two tables which are attached to each other..how do i differentiate between the two tables?or how do i seperate the two tables?is there a way in which i can insert a paragraph/break between the tables..can anyone please help? 1st of all im adding word files to listview.....with diff pname n date...i need to display in different tables...those files im adding/.... plzz see my code then u ll get idea... private void btnsave_Click(object sender, EventArgs e) { List DoctorNames = new List(); List dte = new List(); List pname = new List(); foreach (ListViewItem litem in listView1.Items) { if (DoctorNames.Contains(litem.SubItems[4].Text) == false) DoctorNames.Add(litem.SubItems[4].Text); } List list1 = new List(); List list2 = new List(); object oMissing = System.Reflection.Missing.Value; object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */ Microsoft.Office.Interop.Word._Application oWord; Microsoft.Office.Interop.Word._Document oDoc; oWord = new Microsoft.Office.Interop.Word.Application(); oWord.Visible = true; oDoc = oWord.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing); foreach (string name in DoctorNames) { Microsoft.Office.Interop.Word.Paragraph oPara1; oPara1 = oDoc.Content.Paragraphs.Add(ref oMissing); oPara1.Range.Text = name.ToString(); oPara1.Range.Font.Bold = 1; oPara1.Format.SpaceAfter = 24; //24 pt spacing after paragraph. oPara1.Range.InsertParagraphAfter(); Microsoft.Office.Interop.Word.Paragraph oPara2; oPara2 = oDoc.Content.Paragraphs.Add(ref oMissing); oPara2.Range.Text = "Date:" + dte.ToString(); oPara2.Range.Font.Bold = 1; oPara2.Format.SpaceAfter = 24; //24 pt spacing after paragraph. oPara2.Range.InsertParagraphAfter(); string query = "Select FileName,LineCount from tbl where PName='" + name + "'";
-
I am trying to create 2 separate tables and print them in word, however I end up with two tables which are attached to each other..how do i differentiate between the two tables?or how do i seperate the two tables?is there a way in which i can insert a paragraph/break between the tables..can anyone please help? 1st of all im adding word files to listview.....with diff pname n date...i need to display in different tables...those files im adding/.... plzz see my code then u ll get idea... private void btnsave_Click(object sender, EventArgs e) { List DoctorNames = new List(); List dte = new List(); List pname = new List(); foreach (ListViewItem litem in listView1.Items) { if (DoctorNames.Contains(litem.SubItems[4].Text) == false) DoctorNames.Add(litem.SubItems[4].Text); } List list1 = new List(); List list2 = new List(); object oMissing = System.Reflection.Missing.Value; object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */ Microsoft.Office.Interop.Word._Application oWord; Microsoft.Office.Interop.Word._Document oDoc; oWord = new Microsoft.Office.Interop.Word.Application(); oWord.Visible = true; oDoc = oWord.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing); foreach (string name in DoctorNames) { Microsoft.Office.Interop.Word.Paragraph oPara1; oPara1 = oDoc.Content.Paragraphs.Add(ref oMissing); oPara1.Range.Text = name.ToString(); oPara1.Range.Font.Bold = 1; oPara1.Format.SpaceAfter = 24; //24 pt spacing after paragraph. oPara1.Range.InsertParagraphAfter(); Microsoft.Office.Interop.Word.Paragraph oPara2; oPara2 = oDoc.Content.Paragraphs.Add(ref oMissing); oPara2.Range.Text = "Date:" + dte.ToString(); oPara2.Range.Font.Bold = 1; oPara2.Format.SpaceAfter = 24; //24 pt spacing after paragraph. oPara2.Range.InsertParagraphAfter(); string query = "Select FileName,LineCount from tbl where PName='" + name + "'";
@nisha 2n wrote:
for (int r = 1; r < a; r++)
{
oTable.Cell(r + 1, 1).Range.Text = r.ToString();
oTable.Cell(r + 1, 2).Range.Text = listView1.Items[r - 1].SubItems[2].Text;
oTable.Cell(r + 1, 3).Range.Text = listView1.Items[r - 1].SubItems[7].Text;oTable.Rows[r].Height = oWord.InchesToPoints(0);
}I do not see where you are creating two different tables. Perhaps that code is being called else where? Try:
if(ThisDocument.Tables.Count == 0)
oTable = ThisDoucument.Tables[0];
else
oTable = ThisDoucument.Tables.Add(wrdRng, a, 3, ref oMissing, ref oMissing);oTable.Range.ParagraphFormat.SpaceAfter = 6;
oTable.Cell(1, 1).Range.Text = "SNO";
oTable.Cell(1, 2).Range.Text = "FileName";
oTable.Cell(1, 3).Range.Text = "Total Count";for (int r = 1; r < a; r++)
{oTable.Cell(r + 1, 1).Range.Text = r.ToString();
oTable.Cell(r + 1, 2).Range.Text = listView1.Items[r - 1].SubItems[2].Text;
oTable.Cell(r + 1, 3).Range.Text = listView1.Items[r - 1].SubItems[7].Text;
oTable.Rows[r].Height = oWord.InchesToPoints(0);
}oTable.Columns[1].Width = oWord.InchesToPoints(0); //Change width of columns 1 & 2
oTable.Columns[2].Width = oWord.InchesToPoints(0);
oTable.Columns[3].Width = oWord.InchesToPoints(0);oTable.Rows[1].Range.Font.Bold = 1;
Just make sure you are indexing the correct table in the document. ~TheArch
-
@nisha 2n wrote:
for (int r = 1; r < a; r++)
{
oTable.Cell(r + 1, 1).Range.Text = r.ToString();
oTable.Cell(r + 1, 2).Range.Text = listView1.Items[r - 1].SubItems[2].Text;
oTable.Cell(r + 1, 3).Range.Text = listView1.Items[r - 1].SubItems[7].Text;oTable.Rows[r].Height = oWord.InchesToPoints(0);
}I do not see where you are creating two different tables. Perhaps that code is being called else where? Try:
if(ThisDocument.Tables.Count == 0)
oTable = ThisDoucument.Tables[0];
else
oTable = ThisDoucument.Tables.Add(wrdRng, a, 3, ref oMissing, ref oMissing);oTable.Range.ParagraphFormat.SpaceAfter = 6;
oTable.Cell(1, 1).Range.Text = "SNO";
oTable.Cell(1, 2).Range.Text = "FileName";
oTable.Cell(1, 3).Range.Text = "Total Count";for (int r = 1; r < a; r++)
{oTable.Cell(r + 1, 1).Range.Text = r.ToString();
oTable.Cell(r + 1, 2).Range.Text = listView1.Items[r - 1].SubItems[2].Text;
oTable.Cell(r + 1, 3).Range.Text = listView1.Items[r - 1].SubItems[7].Text;
oTable.Rows[r].Height = oWord.InchesToPoints(0);
}oTable.Columns[1].Width = oWord.InchesToPoints(0); //Change width of columns 1 & 2
oTable.Columns[2].Width = oWord.InchesToPoints(0);
oTable.Columns[3].Width = oWord.InchesToPoints(0);oTable.Rows[1].Range.Font.Bold = 1;
Just make sure you are indexing the correct table in the document. ~TheArch
hii,,,,,, yah...im getting multiple tables..... Actualy my proj is on linecount for Word files...... soo 1st im using list view for add some files .when im adding those files i hav to select diff pysician name n date.........it ill stores into data base((convert MS ACCESS data to MS Word)) n then whn im save that data ,then,,it ll b save in single word doc in different tables..by selectd pysician name n date,.. ....BUT iam getting repeating in one table lik... Dr.Name:Dr.Jhon Date:20/12/2009 Sno| FileName |Count 1 Hobbs.doc |36.31 2 Horn.doc |45.72 3 McMillan.doc |41.49 4 Smith.doc |10.72 Dr.Name:Dr.king Date:22/12/2009 Sno |FileName |Count 1 Hobbs.doc |36.31 2 Horn.doc |45.72 3 McMillan.doc |41.49 4 Smith.doc |10.72 .......................................................................... this is actully i want 2 get.... Dr.Name:Dr.Jhon Date:20/12/2009 Sno| FileName| Count 1 Hobbs.doc |36.31 2 Horn.doc| 45.72 Dr.Name:Dr.king Date:22/12/2009 Sno| FileName |Count 1 McMillan.doc |41.49 2 Smith.doc| 10.72