Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. how do i differentiate between the two tables

how do i differentiate between the two tables

Scheduled Pinned Locked Moved C#
questiondatabasecomhelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nisha 2n
    wrote on last edited by
    #1

    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 + "'";

    L 1 Reply Last reply
    0
    • N nisha 2n

      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 + "'";

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      @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

      N 1 Reply Last reply
      0
      • L Lost User

        @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

        N Offline
        N Offline
        nisha 2n
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups