C# WinForm窗体中,嵌入类似于Excel表格
你这个问题我也遇到 了,纠结了好久,office2003用WEBBROWSER 这个方法可以,可2007不行,不过我最后找到办法解决了,理解寻找解决办法人的心情,所以这里贡献出来给大家。
DsoFramer_KB311765_x86.exe用这个控件,可以上网去下载,百度或到微软官网下载。
如果下不到也可以找我发。
这个控件可以在WINFORM里面直接把EXCEL引用上来显示在控件里面,就像在操作EXCEL一模一样。
可以在Excel里面先设置好,把标题隐藏,状态栏,编辑栏,滚动条等这些隐藏,这样看起来也看不出是在Excel操作。
也可以在Excel里设置好数据有效性,这样就只能选择,可以设置只允许用户选择指定单元格,其他单元格不能选择。
包括颜色,工作表保护,禁止随便修改。
也可以在Excel里面设置好宏,这里操作也会执行。
如何用winform向excel中插入数据,就好像把excel当?
给您一个简单一点的方案,不过前提是本地数据库连接。
1、按数据库表的方式建立excel表,但是列名最好是英文的;2、用odbc建立“Microsoft Excel Driver (*.xls)”的数据库连接;3、用ado.net之类的链接控件链接你建好的odbc数据源;4、按照常规的表操作方式进行数据操作就行了。
只是对excel的操作commit和rollback没用,直接delete、insert和update就行了。
C#窗体程序 如何在光标处插入指定文本。
/// 在当前光标位置插入内容 /// /// 内容 public void SelectionInsertText(string text) { Word.Selection currentSelection = Application.Selection; // Store the user's current Overtype selection bool userOvertype = Application.Options.Overtype; // Make sure Overtype is turned off. if (Application.Options.Overtype) { Application.Options.Overtype = false; } // Test to see if selection is an insertion point. if (currentSelection.Type == Word.WdSelectionType.wdSelectionIP) { //currentSelection.TypeText("Inserting at insertion point. "); currentSelection.TypeText(text); currentSelection.TypeParagraph(); } else { if (currentSelection.Type == Word.WdSelectionType.wdSelectionNormal) { // Move to start of selection. if (Application.Options.ReplaceSelection) { object direction = Word.WdCollapseDirection.wdCollapseStart; currentSelection.Collapse(ref direction); } //currentSelection.TypeText("Inserting before a text block. "); currentSelection.TypeText(text); currentSelection.TypeParagraph(); } else { // Do nothing. } } // Restore the user's Overtype selection Application.Options.Overtype = userOvertype; } 展开
C#如何给word文档添加水印
引用spire.doc.dll, 使用下面的代码 添加图片水印: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 using Spire.Doc; using System.Drawing; namespace Image_Watermark { class Program { static void Main(string[] args) { //加载Word文档 Document document = new Document(); document.LoadFromFile("Test.docx"); //新建一个图片水印对象并添加为待设置水印的图片 PictureWatermark picture = new PictureWatermark(); picture.Picture = System.Drawing.Image.FromFile("logo.png"); //缩放图片大小 picture.Scaling = 10; //将图片设置为文档的水印 document.Watermark = picture; //保存文档 document.SaveToFile("图片水印.docx", FileFormat.Docx2010); document.Close(); } } } 添加文字水印: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 using Spire.Doc; using System.Drawing; using Spire.Doc.Documents; namespace Text_Watermark { class Program { static void Main(string[] args) { //加载Word文档 Document document = new Document(); document.LoadFromFile("Test.docx"); //新建一个文本水印对象,并添加待设置为水印的文本 TextWatermark txtWatermark = new TextWatermark(); txtWatermark.Text = "内部使用"; //设置文本的字体大小,颜色及文本的排列方式 txtWatermark.FontSize = 45; txtWatermark.Color = Color.Green; txtWatermark.Layout = WatermarkLayout.Diagonal; //将该文本设置为word文档的水印 document.Watermark = txtWatermark; //保存文本 document.SaveToFile("文本水印.docx", FileFormat.Docx2010); document.Close(); } } }
可以在winform窗体里添加显示FLASH动画吗?该怎么做?
用什么开发工具? 在C#.net2003上,工具箱上添加控件的对话框里,“COM Component”标签里选Shockwave Flash Object,工具箱里就能看到“Shockwave Flash Object”这个控件了。
然后在窗体上添加一个“Shockwave Flash Object”,默认名称是axShockwaveFlash1。
在Form_Load里添加代码: axShockwaveFlash1.Movie = " "; axShockwaveFlash1.Play(); 就可以播放了。
上面的链接是我在 上随便找的链接,你换成你想播放的flash地址就行了,本机的也行。
C#操作word怎么改变文字方向
用word最好,代码是 using Word; 下面的例子中包括C#对Word文档的创建、插入表格、设置样式等操作:(例子中代码有些涉及数据信息部分被省略,重要是介绍一些C#操作word文档的方法) public string CreateWordFile(string CheckedInfo) ...{ string message = ""; try ...{ Object Nothing = System.Reflection.Missing.Value; Directory.CreateDirectory("C:/CNSI"); //创建文件所在目录 string name = "CNSI_" + DateTime.Now.ToShortString()+".doc"; object filename = "C://CNSI//" + name; //文件保存路径 //创建Word文档 Word.Application WordApp = new Word.ApplicationClass(); Word.Document WordDoc = WordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing); //添加页眉 WordApp.ActiveWindow.View.Type = WdViewType.wdOutlineView; WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekPrimaryHeader; WordApp.ActiveWindow.ActivePane.Selection.InsertAfter("[页眉内容]"); WordApp.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight;//设置右对齐 WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekMainDocument;//跳出页眉设置 WordApp.Selection.ParagraphFormat.LineSpacing = 15f;//设置文档的行间距 //移动焦点并换行 object count = 14; object WdLine = Word.WdUnits.wdLine;//换一行; WordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//移动焦点 WordApp.Selection.TypeParagraph();//插入段落 //文档中创建表格 Word.Table newTable = WordDoc.Tables.Add(WordApp.Selection.Range, 12, 3, ref Nothing, ref Nothing); //设置表格样式 newTable.Borders.OutsideLineStyle = Word.WdLineStyle.wdLineStyleThickThinLargeGap; newTable.Borders.InsideLineStyle = Word.WdLineStyle.wdLineStyleSingle; newTable.Columns[1].Width = 100f; newTable.Columns[2].Width = 220f; newTable.Columns[3].Width = 105f; //填充表格内容 newTable.Cell(1, 1).Range.Text = "产品详细信息表"; newTable.Cell(1, 1).Range.Bold = 2;//设置单元格中字体为粗体 //合并单元格 newTable.Cell(1, 1).Merge(newTable.Cell(1, 3)); WordApp.Selection.Cells.VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;//垂直居中 WordApp.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;//水平居中 //填充表格内容 newTable.Cell(2, 1).Range.Text = "产品基本信息"; newTable.Cell(2, 1).Range.Font.Color = Word.WdColor.wdColorDarkBlue;//设置单元格内字体颜色 //合并单元格 newTable.Cell(2, 1).Merge(newTable.Cell(2, 3)); WordApp.Selection.Cells.VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter; //填充表格内容 newTable.Cell(3, 1).Range.Text = "品牌名称:"; newTable.Cell(3, 2).Range.Text = BrandName; //纵向合并单元格 newTable.Cell(3, 3).Select();//选中一行 object moveUnit = Word.WdUnits.wdLine; object moveCount = 5; object moveExtend = Word.WdMovementType.wdExtend; WordApp.Selection.MoveDown(ref moveUnit, ref moveCount, ref moveExtend); WordApp.Selection.Cells.Merge(); //插入图片 string FileName = Picture;//图片所在路径 object LinkToFile = false; object SaveWithDocument = true; object Anchor = WordDoc.Application.Selection.Range; WordDoc.Application.ActiveDocument.InlineShapes.AddPicture(FileName, ref LinkToFile, ref SaveWithDocument, ref Anchor); WordDoc.Application.ActiveDocument.InlineShapes[1].Width = 100f;//图片宽度 WordDoc.Application.ActiveDocument.InlineShapes[1].Height = 100f;//图片高度 //将图片设置为四周环绕型 Word.Shape s = WordDoc.Application.ActiveDocument.InlineShapes[1].ConvertToShape(); s.WrapFormat.Type = Word.WdWrapType.wdWrapSquare; newTable.Cell(12, 1).Range.Text = "产品特殊属性"; newTable.Cell(12, 1).Merge(newTable.Cell(12, 3)); //在表格中增加行 WordDoc.Content.Tables[1].Rows.Add(ref Nothing); WordDoc.Paragraphs.Last.Range.Text = "文档创建时间:" + DateTime.Now.ToString();//“落款” WordDoc.Paragraphs.Last.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight; //文件保存 WordDoc.SaveAs(ref filename, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing); WordDoc.Close(ref Nothing, ref Nothing, ref Nothing); WordApp.Quit(ref Nothing, ref Nothing, ref Nothing); message=name+"文档生成成功,以保存到C:CNSI下"; } catch ...{ message = "文件导出异常!"; } return message; } 好好琢磨琢磨吧。
如何在C#中使用OpenXml操作Word模版,向Bookmark中填充数据。
对word的操作给你这个是把word打开 并把其内容 复制出来 你参考一下吧 //btnFindFile_Click(object sender, EventArgs e)中应该按照路径找章节编码,暂时没有实现; private Microsoft.Office.Interop.Word.ApplicationClass oWordApplic; private Microsoft.Office.Interop.Word.Document oDoc; object missing = System.Reflection.Missing.Value; private List SQlStrList = new List(); private ArrayList arr = new ArrayList(); private string ZJBM = ""; private int C = 0; public frm导入Word() { InitializeComponent(); } public class objclass { public string _value; public string _text; public override string ToString() { return _text; } public objclass(string v, string t) { _text = t; _value = v; } public override bool Equals(object obj) { return obj.ToString() == this._value; } } private void frmKZQKDR_Load(object sender, EventArgs e) { this.cmbTX.SelectedIndex = 0; 基础类.buildTree.Bound难易程度(cmbNYCD); cmbNYCD.SelectedIndex = -1; 基础类.buildTree.Bound题目类型(cmbTX); } private void btnFindFile_Click(object sender, EventArgs e)//将word内容导入到RichTextBox中 { openFileDialog1.Filter = "(*.doc)|*.doc"; if (openFileDialog1.ShowDialog(this) == DialogResult.OK) { txtExcelFile.Text = openFileDialog1.FileName; //打开word,拷贝内容至RTF WordHelp(); Open(txtExcelFile.Text); oWordApplic.Selection.WholeStory(); oWordApplic.Selection.Copy(); richTextBox1.Clear(); richTextBox1.Paste(); Clipboard.Clear(); //避免弹出normal.dot被使用的对话框 oWordApplic.NormalTemplate.Saved = true; oDoc.Close(ref missing, ref missing, ref missing); Quit(); start = 0; //从得到的路径获得当前章节编码(尚未实现) ZJBM = ""; } } #region///word用函数 public Microsoft.Office.Interop.Word.ApplicationClass WordApplication { get { return oWordApplic; } } public void WordHelp() { // activate the interface with the COM object of Microsoft Word oWordApplic = new Microsoft.Office.Interop.Word.ApplicationClass(); } public void WordHelp(Microsoft.Office.Interop.Word.ApplicationClass wordapp) { oWordApplic = wordapp; } // Open a file (the file must exists) and activate it public void Open(string strFileName) { object fileName = strFileName; object readOnly = false; object isVisible = true; oDoc = oWordApplic.Documents.Open(ref fileName, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing, ref missing); oDoc.Activate(); } // Open a new document public void Open() { oDoc = oWordApplic.Documents.Add(ref missing, ref missing, ref missing, ref missing); oDoc.Activate(); } public void Quit() { oWordApplic.Application.Quit(ref missing, ref missing, ref missing); } /// 打开Word文档,并且返回对象oDoc /// 完整Word文件路径+名称 /// 返回的Word.Document oDoc对象 public Microsoft.Office.Interop.Word.Document CreateWordDocument(string FileName, bool HideWin) { if (FileName == "") return null; oWordApplic.Visible = HideWin; oWordApplic.Caption = ""; oWordApplic.Options.CheckSpellingAsYouType = false; oWordApplic.Options.CheckGrammarAsYouType = false; Object filename = FileName; Object ConfirmConversions = false; Object ReadOnly = false; Object AddToRecentFiles = false; Object PasswordDocument = System.Type.Missing; Object PasswordTemplate = System.Type.Missing; Object Revert = System.Type.Missing; Object WritePasswordDocument = System.Type.Missing; Object WritePasswordTemplate = System.Type.Missing; Object Format = System.Type.Missing; Object Encoding = System.Type.Missing; Object Visible = System.Type.Missing; Object OpenAndRepair = System.Type.Missing; Object DocumentDirection = System.Type.Missing; Object NoEncodingDialog = System.Type.Missing; Object XMLTransform = System.Type.Missing; try { Microsoft.Office.Interop.Word.Document wordDoc = oWordApplic.Documents.Open(ref filename, ref ConfirmConversions, ref ReadOnly, ref AddToRecentFiles, ref PasswordDocument, ref PasswordTemplate, ref Revert, ref WritePasswordDocument, ref WritePasswordTemplate, ref Format, ref Encoding, ref Visible, ref OpenAndRepair, ref DocumentDirection, ref NoEncodingDialog, ref XMLTransform); return wordDoc; } catch (Exception ex) { MessageBox.Show(ex.Message); return null; } } public void SaveAs(Microsoft.Office.Interop.Word.Document oDoc, string strFileName) { object fileName = strFileName; if (File.Exists(strFileName)) { if (MessageBox.Show("文件'" + strFileName + "'已经存在,选确定覆盖原文件,选取消退出操作!", "警告", MessageBoxButtons.O...
c# 这些字必须以大写字母开头:button1
目前,我暂时知道的有:1你在WORD中同时按Ctrl+A时,可以选择整篇文章.2.F1 显示当前程序或者windows的帮助内容。
F2 当你选中一个文件的话,这意味着“重命名”F3 当你在桌面上的时候是打开“查找:所有文件” 对话框下面是我收集的一些技巧:问:WORD里边怎样设置每页不同的页眉?如何使不同的章节显示的页眉不同?答:分节,每节可以设置不同的页眉。
文件——页面设置——版式——页眉和页脚——首页不同问:请问word中怎样让每一章用不同的页眉?怎么我现在只能用一个页眉,一改就全部改了? 答:在插入分隔符里,选插入分节符,可以选连续的那个,然后下一页改页眉前,按一下“同前”钮,再做的改动就不影响前面的了。
简言之,分节符使得它们独立了。
这个工具栏上的“同前”按钮就显示在工具栏上,不过是图标的形式,把光标移到上面就显示出”同前“两个字来了问:如何合并两个WORD文档,不同的页眉需要先写两个文件,然后合并,如何做?答:页眉设置中,选择奇偶页不同/与前不同等选项问:WORD编辑页眉设置,如何实现奇偶页不同? 比如:单页 浙江大学学位论文,这一个容易设;双页:(每章标题),这一个有什么技巧啊 ?答:插入节分隔符,与前节设置相同去掉,再设置奇偶页不同问:怎样使WORD文档只有第一页没有页眉,页脚?答:页面设置-页眉和页脚,选首页不同,然后选中首页页眉中的小箭头,格式-边框和底纹,选择无,这个只要在“视图”——“页眉页脚”,其中的页面设置里,不要整个文档,就可以看到一个“同前”的标志,不选,前后的设置情况就不同了。
问:如何从第三页起设置页眉?答:在第二页末插入分节符,在第三页的页眉格式中去掉同前节,如果第一、二页还有页眉,把它设置成正文就可以了●在新建文档中,菜单—视图—页脚—插入页码—页码格式—起始页码为0,确定;●菜单—文件—页面设置—版式—首页不同,确定;●将光标放到第一页末,菜单—文件—页面设置—版式—首页不同—应用于插入点之后,确定。
第2步与第三步差别在于第2步应用于整篇文档,第3步应用于插入点之后。
这样,做两次首页不同以后,页码从第三页开始从1编号,完成。
问:WORD页眉自动出现一根直线,请问怎么处理?答:格式从“页眉”改为“清除格式”,就在“格式”快捷工具栏最左边;选中页眉文字和箭头,格式-边框和底纹-设置选无问:页眉一般是---------,上面写上题目或者其它,想做的是把这根线变为双线,WORD中修改页眉的那根线怎么改成双线的? 答:按以下步骤操作去做:●选中页眉的文字,包括最后面的箭头●格式-边框和底纹●选线性为双线的●在预览里,点击左下小方块,预览的图形会出现双线●确定▲上面和下面自己可以设置,点击在预览周围的四个小方块,页眉线就可以在不同的位置问:Word中的脚注如何删除?把正文相应的符号删除,内容可以删除,但最后那个格式还在,应该怎么办?答:步骤如下:1、切换到普通视图,菜单中“视图”——“脚注”,这时最下方出现了尾注的编辑栏。
2、在尾注的下拉菜单中选择“尾注分隔符”,这时那条短横线出现了,选中它,删除。
3、再在下拉菜单中选择“尾注延续分隔符”,这是那条长横线出现了,选中它,删除。
4、切换回到页面视图尾注和脚注应该都是一样的问:Word 里面有没有自动断词得功能?常常有得单词太长了,如果能设置一下自动断词就好了答:在工具—语言—断字—自动断字,勾上,word还是很强大的问:如何将word文档里的繁体字改为简化字?答:工具—语言—中文简繁转换问:怎样微调WORD表格线?WORD表格上下竖线不能对齐,用鼠标拖动其中一条线,可是一拖就跑老远,想微调表格竖线让上下对齐,请问该怎么办?答:选定上下两个单元格,然后指定其宽度就可以对齐了,再怎么拉都行press "Alt",打开绘图,其中有个调整坐标线,单击,将其中水平间距与垂直间距都调到最小值即可。
打开绘图,然后在左下脚的绘图网格里设置,把水平和垂直间距设置得最小。
问:怎样微调word表格线?我的word表格上下竖线不能对齐,用鼠标拖动其中一条线,可是一拖就跑老远,我想微调表格竖线让上下对齐,请问该怎么办? 答:可以如下操作:●按住ctl键还是shift,你have a try●double click the line, try it :)●打开绘图,设置一下网格(在左下角)。
使水平和垂直都为最小,试一把!?●press "Alt"问:怎么把word文档里已经有的分页符去掉?答:先在工具——> 选项——> 视图——> 格式标记,选中全部,然后就能够看到分页符,delete就ok了。
问:Word中下标的大小可以改的吗?答:格式—字体问:Word里怎么自动生成目录啊?答:用“格式>>样式和格式”编辑文章中的小标题,然后插入->索引和目录问:Word的文档结构图能否整个复制? 论文要写目录了,不想再照着文档结构图输入一遍,有办法复制粘贴过来吗?答:可以自动生成的,插入索引目录。
问:做目录的时候有什么办法时右边的页码对齐?比如:1.1 标题...............................11.2 标题...............................2答:画表格,然后把页码都放到一...
VS 2013 C#winform 怎么导入背景音乐
可以添加afxmediaplayer控件,然后把该控件的visible属性设置为false实现隐藏,并在winform的load事件中添加要播放的背景音乐。
在afxmediaplayer控件属性栏中把AutoStart设置成为true(其实默认是true),只要文件路径设置正确,则文件将会自动播放。
设置路径的代码为: this.axMediaPlayer1.URL= musicpath;//其中musicpath为背景音乐的路径...
转载请注明出处51数据库 » winform 嵌入 word
都严肃点儿