日期:2014-05-17 浏览次数:20480 次
object Nothing = System.Reflection.Missing.Value; Word.Application attachApp = new Application(); object type = WdBreakType.wdSectionBreakContinuous; Word.Document attachDoc = attachApp.Documents.Open(ref docFile, 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); attachDoc.Select(); attachApp.Selection.WholeStory(); attachDoc.Sections[1].Range.Copy(); object attach_ServiceContent = "attach_ServiceContent"; doc.Bookmarks.get_Item(ref attach_ServiceContent).Range.InsertBreak(ref type); doc.Bookmarks.get_Item(ref attach_ServiceContent).Range.PasteAndFormat(WdRecoveryType.wdPasteDefault); attachApp.NormalTemplate.Saved = true; object doNotSaveChanges = WdSaveOptions.wdDoNotSaveChanges; attachDoc.Close(ref doNotSaveChanges, ref Nothing, ref Nothing); attachApp.Quit(ref doNotSaveChanges, ref Nothing, ref Nothing);
object clipboardData = Clipboard.GetData("userEntites"); this.btnPaste.Enabled = (clipboardData != null); private void btnCopy_Click(object sender, EventArgs e) { // 读取数据 List<BaseUserEntity> userEntites = new List<BaseUserEntity>(); for (int i=0; i<this.DTUser.Rows.Count; i++) { BaseUserEntity userEntity = new BaseUserEntity(this.DTUser.Rows[i]); userEntites.Add(userEntity); } // 复制到剪切板 Clipboard.SetData("userEntites", userEntites); this.btnPaste.Enabled = true; } private void btnPaste_Click(object sender, EventArgs e) { object clipboardData = Clipboard.GetData("userEntites"); if (clipboardData != null) { List<BaseUserEntity> userEntites = (List<BaseUserEntity>)clipboardData; string[] addUserIds = new string[userEntites.Count]; for (int i = 0; i < userEntites.Count; i++) { addUserIds[i] = userEntites[i].Id.ToString(); } // 添加用户到角色 ServiceManager.Instance.RoleService.AddUserToRole(this.UserInfo, this.TargetRoleId, addUserIds); // 加载窗体 this.FormOnLoad(); // 设置按钮状态 this.SetControlState(); } }
------解决方案--------------------
用富文本框把word中数据插入数据库.
然后用label读取出来.效果和原本一样.