Click here to Skip to main content
15,904,494 members
Home / Discussions / C#
   

C#

 
GeneralRe: Toolbar by .net Pin
Pete O'Hanlon17-Dec-09 1:46
mvePete O'Hanlon17-Dec-09 1:46 
GeneralRe: Toolbar by .net Pin
EliottA17-Dec-09 3:04
EliottA17-Dec-09 3:04 
QuestionMySQl Database Backup Pin
anishkannan16-Dec-09 22:38
anishkannan16-Dec-09 22:38 
QuestionWeb To Desktop! Pin
Sr...Frank16-Dec-09 22:19
Sr...Frank16-Dec-09 22:19 
AnswerRe: Web To Desktop! Pin
dan!sh 17-Dec-09 0:26
professional dan!sh 17-Dec-09 0:26 
QuestionAssignment Problem Pin
eyalle16-Dec-09 20:44
eyalle16-Dec-09 20:44 
AnswerRe: Assignment Problem Pin
eyalle16-Dec-09 22:17
eyalle16-Dec-09 22:17 
QuestionHow to separate word tables for differnet files Pin
@nisha 2n16-Dec-09 19:46
@nisha 2n16-Dec-09 19:46 
hi....now im doing work on Line count for word documents...1st i hav 2 select Dr name n date n then add files in listview and then if i go for save those files will save in ms word table as separately as Different DR name n Date wise in seperate tables...


....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




Here is my code...

private void btnsave_Click(object sender, EventArgs e)
{
for (int k = 1; k < listView1.Items.Count; k++)
{
if (listView1.Items[k - 1].Text != listView1.Items[k].Text)
{
dte.Add(listView1.Items[k - 1].Text);
dte.Add(listView1.Items[k].Text);
}
if (listView1.Items[k - 1].SubItems[3].Text != listView1.Items[k].SubItems[3].Text)
{
pname.Add(listView1.Items[k - 1].SubItems[3].Text);
pname.Add(listView1.Items[k].SubItems[3].Text);
}
}
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);


for (int k = 0; k < dte.Count; k++)
{
Microsoft.Office.Interop.Word.Paragraph oPara1;
oPara1 = oDoc.Content.Paragraphs.Add(ref oMissing);
oPara1.Range.Text = pname[k].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[k].ToString();
oPara2.Range.Font.Bold = 1;
oPara2.Format.SpaceAfter = 24; //24 pt spacing after paragraph.
oPara2.Range.InsertParagraphAfter();

int a = listView1.Items.Count + 1;
Microsoft.Office.Interop.Word.Table oTable;

Microsoft.Office.Interop.Word.Range wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
oTable = oDoc.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 = listView1.Items[r - 1].SubItems[1].Text;
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[5].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;

}
MessageBox.Show("Save Successfully");
}


}
}


plzz...help me ............thanquuu....
AnswerRe: How to separate word tables for differnet files Pin
Abhinav S16-Dec-09 21:53
Abhinav S16-Dec-09 21:53 
QuestionOn A Positive Note... Pin
Roger Wright16-Dec-09 19:22
professionalRoger Wright16-Dec-09 19:22 
AnswerRe: On A Positive Note... Pin
dan!sh 16-Dec-09 20:36
professional dan!sh 16-Dec-09 20:36 
AnswerRe: On A Positive Note... Pin
Rob Philpott16-Dec-09 23:03
Rob Philpott16-Dec-09 23:03 
AnswerRe: On A Positive Note... Pin
PIEBALDconsult17-Dec-09 5:10
mvePIEBALDconsult17-Dec-09 5:10 
Questionreport viewer Pin
ali- kanju216-Dec-09 19:22
ali- kanju216-Dec-09 19:22 
AnswerRe: report viewer Pin
ali- kanju216-Dec-09 20:22
ali- kanju216-Dec-09 20:22 
QuestionNNTP Coding Question... Pin
Member 259847816-Dec-09 17:41
Member 259847816-Dec-09 17:41 
AnswerRe: NNTP Coding Question... Pin
Migounette17-Dec-09 4:00
Migounette17-Dec-09 4:00 
QuestionCreating a Collection of Widgets Pin
cron-fed16-Dec-09 13:51
cron-fed16-Dec-09 13:51 
AnswerRe: Creating a Collection of Widgets Pin
PIEBALDconsult16-Dec-09 13:56
mvePIEBALDconsult16-Dec-09 13:56 
GeneralRe: Creating a Collection of Widgets Pin
cron-fed16-Dec-09 14:26
cron-fed16-Dec-09 14:26 
GeneralRe: Creating a Collection of Widgets Pin
PIEBALDconsult16-Dec-09 17:09
mvePIEBALDconsult16-Dec-09 17:09 
AnswerRe: Creating a Collection of Widgets Pin
_Maxxx_16-Dec-09 14:29
professional_Maxxx_16-Dec-09 14:29 
AnswerRe: Creating a Collection of Widgets Pin
BillWoodruff16-Dec-09 15:30
professionalBillWoodruff16-Dec-09 15:30 
GeneralRe: Creating a Collection of Widgets Pin
Subin Mavunkal16-Dec-09 20:23
Subin Mavunkal16-Dec-09 20:23 
GeneralRe: Creating a Collection of Widgets Pin
cron-fed17-Dec-09 7:15
cron-fed17-Dec-09 7:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.