本文整理汇总了C#中System.Windows.Forms.Document.LoadFromFile方法的典型用法代码示例。如果您正苦于以下问题:C# Document.LoadFromFile方法的具体用法?C# Document.LoadFromFile怎么用?C# Document.LoadFromFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.Document
的用法示例。
在下文中一共展示了Document.LoadFromFile方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: button1_Click
private void button1_Click(object sender, EventArgs e)
{
//Create word document
Document document = new Document();
//load a document
document.LoadFromFile(@"..\..\..\..\..\..\Data\Editing.doc");
//Get a paragraph
Paragraph paragraph = document.Sections[0].AddParagraph();
//Append Text
paragraph.AppendText("Editing sample");
//Save doc file.
document.SaveToFile("Sample.doc", FileFormat.Doc);
//Launching the MS Word file.
WordDocViewer("Sample.doc");
}
示例2: button1_Click
private void button1_Click(object sender, EventArgs e)
{
string fileName = OpenFile();
string fileMerge = OpenFile();
if ((!string.IsNullOrEmpty(fileName)) && (!string.IsNullOrEmpty(fileMerge)))
{
//Create word document
Document document = new Document();
document.LoadFromFile(fileName,FileFormat.Doc);
Document documentMerge = new Document();
documentMerge.LoadFromFile(fileMerge, FileFormat.Doc);
foreach( Section sec in documentMerge.Sections)
{
document.Sections.Add(sec.Clone());
}
//Save doc file.
document.SaveToFile("Sample.doc", FileFormat.Doc);
//Launching the MS Word file.
WordDocViewer("Sample.doc");
}
}
示例3: button1_Click
private void button1_Click(object sender, EventArgs e)
{
List<DictionaryEntry> list = new List<DictionaryEntry>();
DataSet dsData = new DataSet();
dsData.ReadXml(@"..\..\..\..\..\..\Data\Orders.xml");
//Create word document
Document document = new Document();
document.LoadFromFile(@"..\..\..\..\..\..\Data\Invoice.doc");
DictionaryEntry dictionaryEntry = new DictionaryEntry("Customer", string.Empty);
list.Add(dictionaryEntry);
dictionaryEntry = new DictionaryEntry("Order", "Customer_Id = %Customer.Customer_Id%");
list.Add(dictionaryEntry);
document.MailMerge.ExecuteWidthNestedRegion(dsData, list);
//Save doc file.
document.SaveToFile("Sample.doc", FileFormat.Doc);
//Launching the MS Word file.
WordDocViewer("Sample.doc");
}
示例4: button1_Click
private void button1_Click(object sender, EventArgs e)
{
//Create word document
Document document = new Document();
document.LoadFromFile(@"..\..\..\..\..\..\Data\Word.doc");
//Save doc file.
document.SaveToFile("Sample.html", FileFormat.Html);
//Launching the MS Word file.
WordDocViewer("Sample.html");
}
示例5: button2_Click
/*******************************************************************************
* This is a test button labeled "save as pdf" on the create new progress note form
* This is the code to load from a file and read from that file to a new fileformat
********************************************************************************/
private void button2_Click(object sender, EventArgs e)
{
try
{
Document document = new Document();
document.LoadFromFile("Test.txt");
document.SaveToFile("PDFTest.pdf", FileFormat.PDF);
}
catch (Exception ex)
{
MessageBox.Show("The file could not be saved: " + ex.Message);
}
}
示例6: button1_Click
private void button1_Click(object sender, EventArgs e)
{
string fileName = OpenFile();
if (!string.IsNullOrEmpty(fileName))
{
//Create word document
Document document = new Document();
document.LoadFromFile(fileName,FileFormat.Doc,this.textBox1.Text);
//Save doc file.
document.SaveToFile("Sample.doc", FileFormat.Doc);
//Launching the MS Word file.
WordDocViewer("Sample.doc");
}
}
示例7: button1_Click
private void button1_Click(object sender, EventArgs e)
{
Document document = new Document();
//Loading documetn with macros.
document.LoadFromFile(@"../../../../../../Data/Macros.docm", FileFormat.Docm);
//Removes the macros from the document.
document.ClearMacros();
//Save docm file.
document.SaveToFile("Sample.docm", FileFormat.Docm);
//Launching the MS Word file.
WordDocViewer("Sample.docm");
}
示例8: button1_Click
private void button1_Click(object sender, EventArgs e)
{
//Create word document
Document document = new Document();
//load a document
document.LoadFromFile(@"..\..\..\..\..\..\Data\FindAndReplace.doc");
//Replace text
document.Replace(this.textBox1.Text, this.textBox2.Text,true,true);
//Save doc file.
document.SaveToFile("Sample.doc", FileFormat.Doc);
//Launching the MS Word file.
WordDocViewer("Sample.doc");
}
示例9: ConvertWordToCSVFile
private string ConvertWordToCSVFile(OpenFileDialog file)
{
string filename = "";
string newFilename = "";
if (file.OpenFile() != null)
{
//string for converted filename
filename = @"tmp\" + Path.GetFileNameWithoutExtension(file.FileName) + "_converted.txt";
//Start new document and load from selected file
Document doc = new Document();
doc.LoadFromFile(Path.GetFullPath(@"" + file.FileName));
//check to see if file exists, if it does clear it
if (!File.Exists(@"" + filename))
{
//Log file did not exist
Directory.CreateDirectory(@"tmp");
File.Create(@"" + filename).Close();
Debug.WriteLine("File doesn't exist");
}
else
{
//Clear File
File.WriteAllText(@"" + filename, string.Empty);
Debug.WriteLine("File Cleared");
}
//save converted format to new text file
doc.SaveToFile(@"" + filename, FileFormat.Txt);
}
file.FileName = @"" + filename;
Stream convertFile = null;
if ((convertFile = file.OpenFile()) != null)
{
try
{
//items for
string line;
string newLine;
string finalLine = "";
List<string> lineList = new List<string>();
char[] seperators = ",".ToCharArray();
//streamReader to read csv file
StreamReader textReader = new StreamReader(convertFile);
while ((line = textReader.ReadLine()) != null)
{
//check if line is empty of if first character is a number
if (!string.IsNullOrEmpty(line) && char.IsDigit(line[0]))
{
finalLine = "";
lineList.Clear();
newLine = line.Trim().Replace("\t", ",").Replace(",,", ",").Replace(",,,", ",");
newFilename = @"tmp\" + Path.GetFileNameWithoutExtension(file.FileName) + "_import.csv";
//if last character is a comma delete the comma
while (newLine[newLine.Length - 1].Equals(","))
{
newLine = newLine.Remove(newLine.Length - 1, 1);
}
string[] lineArray = newLine.Split(seperators, 3);
foreach (string value in lineArray)
{
lineList.Add(value.Trim());
}
//final line with commas seperating values
finalLine = string.Join(",", lineList);
if (!File.Exists(@"" + newFilename))
{
//Log file did not exist
Directory.CreateDirectory(@"outputs");
Debug.WriteLine("Log files does not exist");
File.Create(@"" + newFilename).Close();
}
//Write to log file
using (StreamWriter csvWriter = File.AppendText(@"" + newFilename))
{
//Log Format
csvWriter.WriteLine("{0}", finalLine);
csvWriter.Close();
}
}
}
textReader.Close();
convertFile.Close();
//delete file after use
if (File.Exists(Path.GetFullPath(filename)))
{
File.Delete(Path.GetFullPath(filename));
//.........这里部分代码省略.........
示例10: importButton_Click
private void importButton_Click(object sender, EventArgs e)
{
// clears the textbox before a contract is loaded
contract_tb.Clear();
// opening the openfiledialog1 control to allow the user to select a file
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
try
{
//Create a document object
Document document = new Document();
document.LoadFromFile(openFileDialog1.FileName);
/************************************************************
* Drashtee this is where the file gets saved as a .txt files
* named Test, we need it to be saved as something that changes
* so that we dont get the file is in use by another process
* error, do this however you see fit. To test if it works,
* open 1 contract and then try to open another after the first
* contract is successfully loaded
*************************************************************/
//Save doc file to a txt format.
document.SaveToFile("Test.txt", FileFormat.Txt);
}
catch (Exception ex)
{
MessageBox.Show("The file could not be read: " + ex.Message);
}
TextToBox();
}
}
示例11: importButton_Click
private void importButton_Click(object sender, EventArgs e)
{
// clears the textbox before a contract is loaded
contract_tb.Clear();
// opening the openfiledialog1 control to allow the user to select a file
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
try
{
//Create a document object
Document document = new Document();
document.LoadFromFile(openFileDialog1.FileName);
docToTxtName = openFileDialog1.FileName + ".txt";
//Save doc file to a txt format.
document.SaveToFile(docToTxtName, FileFormat.Txt);
document.Close();
}
catch (Exception ex)
{
MessageBox.Show("The file could not be read: " + ex.Message);
}
TextToBox();
}
}