R
Ray
Hi all,
I am a bit of a newbie at C# and am trying to set up a document that I will
be modifying based on values from a database. I am using a word document,
because it is the "official" reporting form required by my company. I can
open the document, and write to bookmarks that I am setting in each table
field, but I need to know how to manipulate a checkbox. Can anyone help me?
I have edited this post because I have added some other code. The document
file I am using is a document that has everything inside a table. I have
bookmarked all the text locations, and have bookmarked the table cell with
one of the checkboxes if that helps. Anyway, below is my code. I just need
to know how to tell my program to expect a checkbox at that location, and
modify it based on the alue of a checkbox in my application.
Thanks in advance for all the help.
Ed
private void CreateWordFile()
{
DateTime myDate;
object oMissing = System.Reflection.Missing.Value;
object oEndOfDoc = "\\endofdoc"; //\endofdoc is a predifined
bookmark.
//Start Word and open template.
Word._Application oWord;
Word._Document oDoc;
oWord = new Word.Application();
oWord.Visible = true;
object fileName = @"C:\Plant Tracker\AMP-108_old.doc";
oDoc = oWord.Documents.Open(ref fileName, ref oMissing, ref
oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref
oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref
oMissing, ref oMissing, ref oMissing, ref oMissing);
//Edit Bookmarks in File.
object oBookMark = "FacNameBkMk";
oDoc.Bookmarks.get_Item(ref oBookMark).Range.Text = "Magnolia
Energy";
oBookMark = "EventDateBkMk";
myDate = Convert.ToDateTime(eventDateTxtBx.Text);
oDoc.Bookmarks.get_Item(ref oBookMark).Range.Text =
myDate.ToShortDateString().ToString();
oBookMark = "EventNumBkMk";
oDoc.Bookmarks.get_Item(ref oBookMark).Range.Text =
eventNoTxtBx.Text;
oBookMark = "TitleBkMk";
oDoc.Bookmarks.get_Item(ref oBookMark).Range.Text =
titleTxtBx.Text;
oBookMark = "SummaryBkMk";
oDoc.Bookmarks.get_Item(ref oBookMark).Range.Text =
summaryTxtBx.Text;
oBookMark = "DetailBkMk";
oDoc.Bookmarks.get_Item(ref oBookMark).Range.Text =
detailTxtBx.Text;
oBookMark = "RespBkMk";
oDoc.Bookmarks.get_Item(ref oBookMark).Range.Text =
caRespTxtBx.Text;
oBookMark = "CADueBkMk";
myDate = Convert.ToDateTime(caDueDateTxtBx.Text);
oDoc.Bookmarks.get_Item(ref oBookMark).Range.Text =
myDate.ToShortDateString().ToString();
oBookMark = "CorrActBkMk";
oDoc.Bookmarks.get_Item(ref oBookMark).Range.Text =
corrActionTxtBx.Text;
oBookMark = "PrepByBkMk";
oDoc.Bookmarks.get_Item(ref oBookMark).Range.Text =
prepByTxtBx.Text;
oBookMark = "PrepDateBkMk";
myDate = Convert.ToDateTime(prepDateTxtBx.Text);
oDoc.Bookmarks.get_Item(ref oBookMark).Range.Text =
myDate.ToShortDateString().ToString();
oBookMark = "PMAppBkMk";
oDoc.Bookmarks.get_Item(ref oBookMark).Range.Text =
pmApprovTxtBx.Text;
oBookMark = "PMDateBkMk";
myDate = Convert.ToDateTime(pmDateTxtBx.Text);
oDoc.Bookmarks.get_Item(ref oBookMark).Range.Text =
myDate.ToShortDateString().ToString();
oBookMark = "FinakChkBkMk";
//How do I access the checkbox that is stored in the table cell
at this bookmark?
// Save as new file with file name of "Incident" + EventNumber +
Date.
myDate = Convert.ToDateTime(eventDateTxtBx.Text);
object saveFileName = @"C:\Plant Tracker\Incident_Report_" +
eventNoTxtBx.Text + "_" + myDate.ToShortDateString().ToString().Replace('/',
'-');
MessageBox.Show(saveFileName.ToString());
oDoc.SaveAs(ref saveFileName, ref oMissing, ref oMissing, ref
oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref
oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref
oMissing, ref oMissing, ref oMissing);
I am a bit of a newbie at C# and am trying to set up a document that I will
be modifying based on values from a database. I am using a word document,
because it is the "official" reporting form required by my company. I can
open the document, and write to bookmarks that I am setting in each table
field, but I need to know how to manipulate a checkbox. Can anyone help me?
I have edited this post because I have added some other code. The document
file I am using is a document that has everything inside a table. I have
bookmarked all the text locations, and have bookmarked the table cell with
one of the checkboxes if that helps. Anyway, below is my code. I just need
to know how to tell my program to expect a checkbox at that location, and
modify it based on the alue of a checkbox in my application.
Thanks in advance for all the help.
Ed
private void CreateWordFile()
{
DateTime myDate;
object oMissing = System.Reflection.Missing.Value;
object oEndOfDoc = "\\endofdoc"; //\endofdoc is a predifined
bookmark.
//Start Word and open template.
Word._Application oWord;
Word._Document oDoc;
oWord = new Word.Application();
oWord.Visible = true;
object fileName = @"C:\Plant Tracker\AMP-108_old.doc";
oDoc = oWord.Documents.Open(ref fileName, ref oMissing, ref
oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref
oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref
oMissing, ref oMissing, ref oMissing, ref oMissing);
//Edit Bookmarks in File.
object oBookMark = "FacNameBkMk";
oDoc.Bookmarks.get_Item(ref oBookMark).Range.Text = "Magnolia
Energy";
oBookMark = "EventDateBkMk";
myDate = Convert.ToDateTime(eventDateTxtBx.Text);
oDoc.Bookmarks.get_Item(ref oBookMark).Range.Text =
myDate.ToShortDateString().ToString();
oBookMark = "EventNumBkMk";
oDoc.Bookmarks.get_Item(ref oBookMark).Range.Text =
eventNoTxtBx.Text;
oBookMark = "TitleBkMk";
oDoc.Bookmarks.get_Item(ref oBookMark).Range.Text =
titleTxtBx.Text;
oBookMark = "SummaryBkMk";
oDoc.Bookmarks.get_Item(ref oBookMark).Range.Text =
summaryTxtBx.Text;
oBookMark = "DetailBkMk";
oDoc.Bookmarks.get_Item(ref oBookMark).Range.Text =
detailTxtBx.Text;
oBookMark = "RespBkMk";
oDoc.Bookmarks.get_Item(ref oBookMark).Range.Text =
caRespTxtBx.Text;
oBookMark = "CADueBkMk";
myDate = Convert.ToDateTime(caDueDateTxtBx.Text);
oDoc.Bookmarks.get_Item(ref oBookMark).Range.Text =
myDate.ToShortDateString().ToString();
oBookMark = "CorrActBkMk";
oDoc.Bookmarks.get_Item(ref oBookMark).Range.Text =
corrActionTxtBx.Text;
oBookMark = "PrepByBkMk";
oDoc.Bookmarks.get_Item(ref oBookMark).Range.Text =
prepByTxtBx.Text;
oBookMark = "PrepDateBkMk";
myDate = Convert.ToDateTime(prepDateTxtBx.Text);
oDoc.Bookmarks.get_Item(ref oBookMark).Range.Text =
myDate.ToShortDateString().ToString();
oBookMark = "PMAppBkMk";
oDoc.Bookmarks.get_Item(ref oBookMark).Range.Text =
pmApprovTxtBx.Text;
oBookMark = "PMDateBkMk";
myDate = Convert.ToDateTime(pmDateTxtBx.Text);
oDoc.Bookmarks.get_Item(ref oBookMark).Range.Text =
myDate.ToShortDateString().ToString();
oBookMark = "FinakChkBkMk";
//How do I access the checkbox that is stored in the table cell
at this bookmark?
// Save as new file with file name of "Incident" + EventNumber +
Date.
myDate = Convert.ToDateTime(eventDateTxtBx.Text);
object saveFileName = @"C:\Plant Tracker\Incident_Report_" +
eventNoTxtBx.Text + "_" + myDate.ToShortDateString().ToString().Replace('/',
'-');
MessageBox.Show(saveFileName.ToString());
oDoc.SaveAs(ref saveFileName, ref oMissing, ref oMissing, ref
oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref
oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref
oMissing, ref oMissing, ref oMissing);