本文整理汇总了C#中System.Windows.Forms.Document.SaveToFile方法的典型用法代码示例。如果您正苦于以下问题:C# Document.SaveToFile方法的具体用法?C# Document.SaveToFile怎么用?C# Document.SaveToFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.Document
的用法示例。
在下文中一共展示了Document.SaveToFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
{
//Open a blank word document as template
Document document = new Document(@"..\..\..\..\..\..\Data\Blank.doc");
//Get the first secition
Section section = document.Sections[0];
//Create a new paragraph or get the first paragraph
Paragraph paragraph
= section.Paragraphs.Count > 0 ? section.Paragraphs[0] : section.AddParagraph();
//Append Text
paragraph.AppendText("Builtin Style:");
foreach (BuiltinStyle builtinStyle in Enum.GetValues(typeof(BuiltinStyle)))
{
paragraph = section.AddParagraph();
//Append Text
paragraph.AppendText(builtinStyle.ToString());
//Apply Style
paragraph.ApplyStyle(builtinStyle);
}
//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();
Section section = document.AddSection();
//page setup
SetPage(section);
//insert header and footer
InsertHeaderAndFooter(section);
//add content
InsertContent(section);
//encrypt document with password specified by textBox1
document.Encrypt(this.textBox1.Text);
//Save doc file.
document.SaveToFile("Sample.doc",FileFormat.Doc);
//Launching the MS Word file.
WordDocViewer("Sample.doc");
}
示例5: 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");
}
}
示例6: button1_Click
private void button1_Click(object sender, EventArgs e)
{
//Create word document
Document document = new Document();
Section section = document.AddSection();
section.PageSetup.PageSize = PageSize.A4;
section.PageSetup.Margins.Top = 72f;
section.PageSetup.Margins.Bottom = 72f;
section.PageSetup.Margins.Left = 89.85f;
section.PageSetup.Margins.Right = 89.85f;
Paragraph paragraph = section.AddParagraph();
paragraph.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Left;
paragraph.AppendPicture(ToPDF.Properties.Resources.Word);
String p1
= "Microsoft Word is a word processor designed by Microsoft. "
+ "It was first released in 1983 under the name Multi-Tool Word for Xenix systems. "
+ "Subsequent versions were later written for several other platforms including "
+ "IBM PCs running DOS (1983), the Apple Macintosh (1984), the AT&T Unix PC (1985), "
+ "Atari ST (1986), SCO UNIX, OS/2, and Microsoft Windows (1989). ";
String p2
= "Microsoft Office Word instead of merely Microsoft Word. "
+ "The 2010 version appears to be branded as Microsoft Word, "
+ "once again. The current versions are Microsoft Word 2010 for Windows and 2008 for Mac.";
section.AddParagraph().AppendText(p1).CharacterFormat.FontSize = 14;
section.AddParagraph().AppendText(p2).CharacterFormat.FontSize = 14;
//Save doc file to pdf.
document.SaveToFile("Sample.pdf", FileFormat.PDF);
//Launching the pdf reader to open.
FileViewer("Sample.pdf");
}
示例7: button1_Click
private void button1_Click(object sender, EventArgs e)
{
//Create word document
Document document = new Document();
Section section = document.AddSection();
//the unit of all measures below is point, 1point = 0.3528 mm
section.PageSetup.PageSize = PageSize.A4;
section.PageSetup.Margins.Top = 72f;
section.PageSetup.Margins.Bottom = 72f;
section.PageSetup.Margins.Left = 89.85f;
section.PageSetup.Margins.Right = 89.85f;
//insert header and footer
InsertHeaderAndFooter(section);
addTable(section);
//Save doc file.
document.SaveToFile("Sample.doc",FileFormat.Doc);
//Launching the MS Word file.
WordDocViewer("Sample.doc");
}
示例8: button1_Click
private void button1_Click(object sender, EventArgs e)
{
//open form
Document document = new Document(@"..\..\..\..\..\..\Data\UserForm.doc");
//load data
using (Stream stream = File.OpenRead(@"..\..\..\..\..\..\Data\User.xml"))
{
XPathDocument xpathDoc = new XPathDocument(stream);
XPathNavigator user = xpathDoc.CreateNavigator().SelectSingleNode("/user");
//fill data
foreach (FormField field in document.Sections[0].Body.FormFields)
{
String path = String.Format("{0}/text()", field.Name);
XPathNavigator propertyNode = user.SelectSingleNode(path);
if (propertyNode != null)
{
switch (field.Type)
{
case FieldType.FieldFormTextInput:
field.Text = propertyNode.Value;
break;
case FieldType.FieldFormDropDown:
DropDownFormField combox = field as DropDownFormField;
for(int i = 0; i < combox.DropDownItems.Count; i++)
{
if (combox.DropDownItems[i].Text == propertyNode.Value)
{
combox.DropDownSelectedIndex = i;
break;
}
if (field.Name == "country" && combox.DropDownItems[i].Text == "Others")
{
combox.DropDownSelectedIndex = i;
}
}
break;
case FieldType.FieldFormCheckBox:
if (Convert.ToBoolean(propertyNode.Value))
{
CheckBoxFormField checkBox = field as CheckBoxFormField;
checkBox.Checked = true;
}
break;
}
}
}
}
//Save doc file.
document.SaveToFile("Sample.doc",FileFormat.Doc);
//Launching the MS Word file.
WordDocViewer("Sample.doc");
}
示例9: button1_Click
private void button1_Click(object sender, EventArgs e)
{
//Create word document
Document document = new Document();
addTable(document.AddSection());
//Save xml file.
document.SaveToFile("Sample.xml",FileFormat.Xml);
//Launching the xml file.
XMLViewer("Sample.xml");
}
示例10: button1_Click
private void button1_Click(object sender, EventArgs e)
{
//Open a blank word document as template
Document document = new Document(@"..\..\..\..\..\..\Data\Blank.doc");
InsertHyberlink(document.Sections[0]);
//Save doc file.
document.SaveToFile("Sample.doc",FileFormat.Doc);
//Launching the MS Word file.
WordDocViewer("Sample.doc");
}
示例11: 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);
}
}
示例12: 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");
}
}
示例13: 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");
}
示例14: 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");
}
示例15: 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));
//.........这里部分代码省略.........