- 2
- 0
- 约1.03万字
- 约 8页
- 2017-06-07 发布于北京
- 举报
C# saveFileDialog1 保存成word文档,并写入内容
浏览:2次 ?时间:2012-02-16 10:40:44
我是这样写的?if (saveFileDialog1.ShowDialog() == DialogResult.OK)? {? StreamWriter sw = new StreamWriter(saveFileDialog1.FileName, true);? sw.Write(那些年,一起追的女孩儿!);? sw.Flush();? sw.Close();? System.IO.FileStream fs = (System.IO.FileStream)saveFileDialog1.OpenFile();//输出文件 ? ? } ? 可是打开文件里面没有写入的内容,是怎么回事?
我在网上收到的代码,大家看看。首先引入类库,Microsoft.Office.Interop.Word,然后进行编程。代码如下:[Copy to clipboard]CODE:? ???using System; ??using System.Collections.Generic; ??using System.ComponentModel; ??using System.Data; ??using System.Drawing; ??using System.Text; ??using System.Windows.Forms; ??using Microsoft.Office.Interop.Word; ? ???namespace WordTest ??{ ? ?public partial class Form1 : Form ? ?{ ? ?object strFileName; ? ?Object Nothing; ? ?Microsoft.Office.Interop.Word.Application myWordApp = new Microsoft.Office.Interop.Word.ApplicationClass(); ? ?Document myWordDoc; ? ?string strC; ? ?? ?public Form1() ? ?{ ? ?InitializeComponent(); ? ?} ? ?? ?private void button1_Click(object sender, EventArgs e) ? ?{ ? ?createWord(); ? ?//openWord(); ? ?} ? ?? ?private void createWord() ? ?{ ? ?strFileName = System.Windows.Forms.Application.StartupPath + test.doc; ? ?if (System.IO.File.Exists((string)strFileName)) ? ?System.IO.File.Delete((string)strFileName); ? ?Object Nothing = System.Reflection.Missing.Value; ? ?myWordDoc = myWordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing); ? ?? ?#region 将数据库中读取得数据写入到word文件中 ? ?? ?strC; ? ?myWordDoc.Paragraphs.Last.Range.Text = strContent; ? ?? ?strC; ? ?myWordDoc.Paragraphs.Last.Range.Text = strContent; ? ?? ?? ?#endregion ? ?? ?//将WordDoc文档对象的内容保存为DOC文档 ? ?myWordDoc.SaveAs(ref strFileName, ref Nothing, ref Nothing, refNothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, refNothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, refNothing, ref Nothing, ref Nothing); ? ?//关闭WordDoc文档对象 ? ?myWordDoc.
您可能关注的文档
- AUTOCAD快捷技能集锦.docx
- AutoCAD快捷绘图命令.doc
- AUTOCAD快捷键命令大全.docx
- AutoCAD快捷键命令大集合.doc
- AutoCAD快捷键必背.doc
- AutoCAD快捷键操作方法.doc
- AutoCAD快捷键笔记[1].doc
- AutoCAD技巧看你知多少.doc
- AUTOCAD操作命令全集.doc
- AUTOCAD数据转换成MAPGIS数据.doc
- 广东省广州省实验中学教育集团2025-2026学年八年级上学期期中考试物理试题(解析版).docx
- 广东省广州大学附属中学2025-2026学年八年级上学期奥班期中物理试题(解析版).docx
- 广东省广州市第八十六中学2025-2026学年八年级上学期期中物理试题(含答案).docx
- 广东省广州市第八十九中学2025-2026学年八年级上学期期中考试物理试题(解析版).docx
- 广东省广州市第二中学2025-2026学年八年级上学期期中考试物理试题(含答案).docx
- 广东省广州市第八十六中学2025-2026学年八年级上学期期中物理试题(解析版).docx
- 广东省广州市第八十九中学2025-2026学年八年级上学期期中考试物理试题(含答案).docx
- 广东省广州市第二中学2025-2026学年八年级上学期期中考试物理试题(解析版).docx
- 2026《中国人寿上海分公司营销员培训体系优化研究》18000字.docx
- 《生物探究性实验教学》中小学教师资格模拟试题.docx
最近下载
- 课题申报书:四川方言口传文化的传承普及与乡土记忆重建研究.docx VIP
- 医院中层干部考核细则一.doc
- 公司生产安全事故应急预案(按照新导则GBT 29639-2020编制).pdf VIP
- 作业批改系统论文.doc VIP
- DB37_T 4406.1-2021 政法机关刑事案件网上协同指南 第1部分:基础数据规范.docx VIP
- DB37_T 4413.4-2021 生态环境数据共享技术规范 第4部分:土壤.docx VIP
- DB11_T 1820-2025 控制性详细规划(街区层面)环境影响评价技术指南.pdf VIP
- DB11_T 1455-2025 电动汽车充电基础设施规划设计标准.pdf VIP
- DB11_T 1033-2025 工业射线探伤辐射安全和防护分级管理要求.pdf VIP
- 北京市西城区2025-2026学年高三(上)期末历史+答案.pdf
原创力文档

文档评论(0)