コード例 #1
0
 public bool open(string wordFile)
 {
     this.objWordApp = new Microsoft.Office.Interop.Word.Application();
     if (this.objWordApp == null)
     {
         textBox1.AppendText("Error: Word could not be started. Check that your office installation and project references are correct.");
         return(false);
     }
     this.objWordApp.Visible = false;
     try
     {
         Microsoft.Office.Interop.Word.Document objDoc = this.objWordApp.Documents.Open(wordFile);
         if (objDoc.Tables.Count == 0)
         {
             textBox1.AppendText("Error: This document contains no tables");
             return(false);
         }
         Microsoft.Office.Interop.Word.Table tbl = objDoc.Tables[1];
         tbl.Range.Copy();
     }
     catch (Exception ex)
     {
         textBox1.AppendText("Error: " + ex.Message);
         return(false);
     }
     return(true);
 }
コード例 #2
0
    private static int CellsWrite(int row, int column, Microsoft.Office.Interop.Word.Table myTable, string txt)
    {
        var mYcellValue = ValuesCells(myTable.Columns[column].Width, txt);

        _CellsWrite(new int[] { row, column }, myTable, mYcellValue);
        return(mYcellValue.Count);
    }
コード例 #3
0
        public void Render(Microsoft.Office.Interop.Word.Table table)
        {
            table.Borders.InsideLineStyle  = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
            table.Borders.OutsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
            table.Range.Font.Name          = "Calibri";

            // 填入表格欄位(Column)名稱
            for (int i = 0; i < table.Columns.Count; i++)
            {
                table.Cell(1, i + 1).Range.Text = MyDataTable.Columns[i].ColumnName;
            }

            // 填入表格資料
            int rowIndex = 2;

            foreach (DataRow row in MyDataTable.Rows)
            {
                int colIndex = 1;
                foreach (DataColumn col in MyDataTable.Columns)
                {
                    table.Cell(rowIndex, colIndex).Range.Text = row[col.ColumnName].ToString();
                    colIndex++;
                }
                rowIndex++;
            }
        }
コード例 #4
0
        private void ExportBasicInfo(ref Microsoft.Office.Interop.Word.Table tb)
        {
            tb.Cell(1, 3).Range.Text = AssessSystemUtility.GetCharacterNameByType(_AssessActivity.AssessCharacterType);
            tb.Cell(1, 5).Range.Text = _AssessActivity.ScopeFrom.ToShortDateString() + " 至 " + _AssessActivity.ScopeTo.ToShortDateString();
            tb.Cell(2, 2).Range.Text = _AssessActivity.ItsEmployee.Account.Name;
            tb.Cell(2, 4).Range.Text = _AssessActivity.ItsEmployee.EmployeeDetails.Gender.Name;
            tb.Cell(2, 6).Range.Text = _AssessActivity.ItsEmployee.EmployeeDetails.Birthday.ToShortDateString();
            tb.Cell(3, 2).Range.Text = _AssessActivity.ItsEmployee.Account.Dept.DepartmentName;
            tb.Cell(3, 4).Range.Text = _AssessActivity.ItsEmployee.Account.Position.Name;
            tb.Cell(3, 6).Range.Text = _AssessActivity.ItsEmployee.Account.Dept.DepartmentLeader.Name;
            tb.Cell(4, 2).Range.Text = _AssessActivity.ItsEmployee.EmployeeDetails.Education.EducationalBackground.Name;
            tb.Cell(4, 4).Range.Text = _AssessActivity.ItsEmployee.EmployeeDetails.Work.ComeDate.ToShortDateString();
            string PersonalChoose = "";

            if (_AssessActivity != null &&
                _AssessActivity.ItsAssessActivityPaper != null &&
                _AssessActivity.ItsAssessActivityPaper.SubmitInfoes != null)
            {
                foreach (SubmitInfo info in _AssessActivity.ItsAssessActivityPaper.SubmitInfoes)
                {
                    if (info.SubmitInfoType.Id == SubmitInfoType.MyselfAssess.Id)
                    {
                        PersonalChoose = info.Choose;
                    }
                }
            }
            tb.Cell(7, 2).Range.Text = PersonalChoose;
        }
コード例 #5
0
        //填充学生报告的基本信息
        public static Microsoft.Office.Interop.Word.Table BaseInfo(Microsoft.Office.Interop.Word.Table tb1, Entity.GaoKaoCard infoGaoKaoCard, Entity.Join_Student infoStudent)
        {
            string strProvinceName = "";

            Entity.Province infoProvince = DAL.Province.ProvinceEntityGet(infoStudent.ProvinceId);
            if (infoProvince != null)
            {
                strProvinceName = infoProvince.ProvinceName;
            }

            if (tb1.Rows.Count == 4)
            {
                //在指定单元格填值
                //第1行
                tb1.Cell(1, 2).Range.Text = infoStudent.StudentName;
                tb1.Cell(1, 4).Range.Text = (infoStudent.Sex == 1 ? "女" : "男");
                //第2行
                tb1.Cell(2, 2).Range.Text = infoStudent.SchoolName;
                tb1.Cell(2, 4).Range.Text = (infoStudent.WenLi == 1 ? "文史" : "理工");
                //第3行
                tb1.Cell(3, 2).Range.Text = strProvinceName;
                tb1.Cell(3, 4).Range.Text = infoStudent.GKYear.ToString();
                //第4行
                tb1.Cell(4, 2).Range.Text = infoGaoKaoCard.KaHao;
                tb1.Cell(4, 4).Range.Text = Basic.TypeConverter.StrToDateStr(DateTime.Now.ToString());
            }
            return(tb1);
        }
コード例 #6
0
ファイル: Form1.cs プロジェクト: radtek/mshan
 public void SetColumnWidth(Microsoft.Office.Interop.Word.Table wordTable)
 {
     wordTable.Columns[1].Width = 110;
     wordTable.Columns[2].Width = 100;
     wordTable.Columns[3].Width = 55;
     wordTable.Columns[4].Width = 190;
 }
コード例 #7
0
 private void AddBasicInfo(ref Microsoft.Office.Interop.Word.Table tb)
 {
     tb.Cell(2, 3).Range.Text  = _Employee.Account.Id.ToString();
     tb.Cell(3, 2).Range.Text  = _Employee.Account.Dept.Name;
     tb.Cell(3, 4).Range.Text  = _Employee.EmployeeDetails.Work.ComeDate.ToShortDateString();
     tb.Cell(5, 2).Range.Text  = _Employee.Account.Name;
     tb.Cell(5, 4).Range.Text  = _Employee.EmployeeDetails.Gender.Name;
     tb.Cell(5, 6).Range.Text  = _Employee.EmployeeDetails.Birthday.ToShortDateString();
     tb.Cell(5, 8).Range.Text  = _Employee.EmployeeDetails.Height.ToString();
     tb.Cell(5, 10).Range.Text = _Employee.EmployeeDetails.Weight.ToString();
     tb.Cell(6, 2).Range.Text  = _Employee.EmployeeDetails.NativePlace;
     tb.Cell(6, 4).Range.Text  = _Employee.EmployeeDetails.PoliticalAffiliation.Name;
     tb.Cell(6, 6).Range.Text  = _Employee.EmployeeDetails.Nationality;
     tb.Cell(6, 8).Range.Text  = _Employee.EmployeeDetails.Education.EducationalBackground.Name;
     tb.Cell(6, 10).Range.Text = _Employee.EmployeeDetails.PhysicalConditions;
     tb.Cell(7, 2).Range.Text  = _Employee.EmployeeDetails.Education.School;
     tb.Cell(7, 4).Range.Text  = _Employee.EmployeeDetails.Education.Major;
     tb.Cell(8, 2).Range.Text  = "身份证:" + _Employee.EmployeeDetails.IDCard.IDCardNo;
     tb.Cell(8, 4).Range.Text  = _Employee.EmployeeDetails.MaritalStatus.Name;
     tb.Cell(9, 2).Range.Text  = _Employee.EmployeeDetails.RegisteredPermanentResidence.RPRAddress;
     tb.Cell(9, 4).Range.Text  = _Employee.EmployeeDetails.RegisteredPermanentResidence.PRPPostCode;
     tb.Cell(10, 2).Range.Text = _Employee.EmployeeDetails.RegisteredPermanentResidence.PRPArea;
     tb.Cell(10, 4).Range.Text = _Employee.EmployeeDetails.RegisteredPermanentResidence.PRPStreet;
     tb.Cell(11, 2).Range.Text = _Employee.EmployeeDetails.Family.FamilyAddress;
     tb.Cell(11, 4).Range.Text = _Employee.EmployeeDetails.Family.PostCode;
     tb.Cell(12, 2).Range.Text = _Employee.EmployeeDetails.Family.FamilyPhone;
     tb.Cell(12, 4).Range.Text = _Employee.Account.MobileNum;
     tb.Cell(12, 6).Range.Text = _Employee.EmployeeDetails.EmergencyContacts;
 }
コード例 #8
0
        public void Render(Microsoft.Office.Interop.Word.Table table)
        {
            table.Borders.InsideLineStyle  = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
            table.Borders.OutsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
            table.Range.Font.Name          = "Calibri";

            // 填入表格資料
            int rowIndex = 1;

            foreach (DataRow row in MyDataTable.Rows)
            {
                ////table.Cell(rowIndex, 1).Range.Font.Bold = 1;
                ////table.Cell(rowIndex, 1).Range.Text = string.Format("{0}{1}({2})",
                ////    row["Project"].ToString(),
                ////    Environment.NewLine,
                ////    row["Skus"].ToString());

                Microsoft.Office.Interop.Word.Range range = table.Cell(rowIndex, 1).Range;

                Microsoft.Office.Interop.Word.Paragraph p1 = range.Paragraphs.Add(range);
                p1.Range.Font.Bold = 0;
                p1.Range.Font.Size = 10;
                p1.Range.Text      = string.Format("({0})", row["Skus"].ToString());

                Microsoft.Office.Interop.Word.Paragraph p2 = range.Paragraphs.Add(range);
                p2.Range.Font.Bold = 1;
                p2.Range.Font.Size = 12;
                p2.Range.Text      = row["Project"].ToString() + Environment.NewLine;

                rowIndex++;
            }
        }
コード例 #9
0
 void AddToCell(Microsoft.Office.Interop.Word.Table table, int rowindex, int colindex, float fontsize, int bold, string text)
 {
     table.Cell(rowindex, colindex).Range.Text      = text;
     table.Cell(rowindex, colindex).Range.Font.Bold = bold;
     table.Cell(rowindex, colindex).Range.Font.Name = "verdana";
     table.Cell(rowindex, colindex).Range.Font.Size = fontsize;
     table.Cell(rowindex, colindex).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;
 }
コード例 #10
0
        public void print_report_2(DataTable dt, DateTime d1, DateTime d2)
        {
            try
            {
                object missing = System.Reflection.Missing.Value;
                Microsoft.Office.Interop.Word.Document report_file = win_word.Documents.Add(ref missing, ref missing, ref missing, ref missing);

                Microsoft.Office.Interop.Word.Paragraph para1 = report_file.Content.Paragraphs.Add(ref missing);
                para1.Range.Text = String.Format("Отчет с {0} по {1}", d1.ToShortDateString(), d2.ToShortDateString());
                para1.Range.InsertParagraphAfter();

                Microsoft.Office.Interop.Word.Table data_table = report_file.Tables.Add(para1.Range, dt.Rows.Count + 1, 9, ref missing, ref missing);
                data_table.Borders.OutsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
                data_table.Borders.InsideLineStyle  = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
                data_table.Cell(1, 1).Range.Text    = "Дата";
                data_table.Cell(1, 2).Range.Text    = "ФИО клиента";
                data_table.Cell(1, 3).Range.Text    = "Код услуги";
                data_table.Cell(1, 4).Range.Text    = "Цена";
                data_table.Cell(1, 5).Range.Text    = "Скидка";
                data_table.Cell(1, 6).Range.Text    = "Итог";
                data_table.Cell(1, 7).Range.Text    = "Доктор";
                data_table.Cell(1, 8).Range.Text    = "Доля";
                data_table.Cell(1, 9).Range.Text    = "Админ";
                //logs(date datetime default CURRENT_TIMESTAMP, name text, service_code int, price int, discount int, final int, doctorcode text, share int, login text);");
                //fill table
                int index = 2;

                foreach (DataRow dr in dt.Rows)
                {
                    data_table.Cell(index, 1).Range.Text = dr["date"].ToString();
                    data_table.Cell(index, 2).Range.Text = dr["name"].ToString();
                    data_table.Cell(index, 3).Range.Text = dr["service_code"].ToString();
                    data_table.Cell(index, 4).Range.Text = dr["price"].ToString();
                    data_table.Cell(index, 5).Range.Text = dr["discount"].ToString();
                    data_table.Cell(index, 6).Range.Text = dr["final"].ToString();
                    data_table.Cell(index, 7).Range.Text = dr["doctorcode"].ToString();
                    data_table.Cell(index, 8).Range.Text = dr["share"].ToString();
                    data_table.Cell(index, 9).Range.Text = dr["login"].ToString();
                    index++;
                }
                SaveFileDialog saveFileDialog1 = new SaveFileDialog();

                saveFileDialog1.Filter           = "doc files (*.docx)|*.docx|All files (*.*)|*.*";
                saveFileDialog1.FilterIndex      = 1;
                saveFileDialog1.RestoreDirectory = true;
                object file_path = "";
                if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    file_path = saveFileDialog1.FileName;
                }

                report_file.SaveAs2(ref file_path);
                report_file.Close(ref missing, ref missing, ref missing);
                report_file = null;
                MessageBox.Show("Document created successfully !");
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }
        }
コード例 #11
0
ファイル: Form1.cs プロジェクト: radtek/mshan
 public int TableColumnName(int pointer, Microsoft.Office.Interop.Word.Table wordTable)
 {
     wordTable.Rows[2].Cells[1].Range.Text = "列名";
     //wordTable.Rows[2].Cells[1].Range.wi = "列名";
     wordTable.Rows[2].Cells[2].Range.Text = "类型";
     wordTable.Rows[2].Cells[3].Range.Text = "是否为空";
     wordTable.Rows[2].Cells[4].Range.Text = "描述";
     return(pointer + 1);
 }
コード例 #12
0
 public void _DesginTable(ref Microsoft.Office.Interop.Word.Table table, List <int> columnWeight)
 {
     for (int i = 0; i < table.Rows.Count; i++)
     {
         for (int j = 0; j < table.Columns.Count; j++)
         {
             table.Cell(i + 1, j + 1).Width = columnWeight[j];
         }
     }
 }
コード例 #13
0
        /// <summary>
        /// 根据需要在table中增加必要的行
        /// </summary>
        private static void AddNeedRow(ref Microsoft.Office.Interop.Word.Table tb, int count, int rowIndex)
        {
            object row = tb.Rows[rowIndex];

            for (int i = 0; i < count - 1; i++)
            {
                tb.Rows[rowIndex].Select();
                tb.Rows.Add(ref row);
            }
        }
コード例 #14
0
 private static bool IsExistRow(Microsoft.Office.Interop.Word.Table table, int row)
 {
     if (table.Rows.Count >= row)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
コード例 #15
0
        private void button13_Click(object sender, EventArgs e)
        {
            object filename = Application.StartupPath + "\\bin\\" + Global.templateName;

            Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application();
            Microsoft.Office.Interop.Word.Document    wordDoc;
            wordDoc = wordApp.Documents.Open(filename);
            wordDoc.ActiveWindow.Visible = false;                              //打开word
            Microsoft.Office.Interop.Word.Table nowtable = wordDoc.Tables[17]; //检索表格

            for (int i = 0; i < dataGridView4.RowCount - 1; i++)
            {
                for (int j = 0; j < dataGridView4.ColumnCount; j++)
                {
                    nowtable.Cell(i + 2, j + 1).Range.InsertAfter(dataGridView4[j, i].Value.ToString());//填充表格
                }
            }

            Microsoft.Office.Interop.Word.Table nowtable1 = wordDoc.Tables[8];//检索表格
            for (int i = 0; i < 26; i++)
            {
                nowtable1.Cell(i + 3, 1).Range.InsertAfter(dataGridView1[0, i + 3].Value.ToString());
                nowtable1.Cell(i + 3, 2).Range.InsertAfter(dataGridView1[1, i + 3].Value.ToString());
                nowtable1.Cell(i + 3, 3).Range.InsertAfter(dataGridView1[0, i + 3].Value.ToString());
                nowtable1.Cell(i + 3, 4).Range.InsertAfter(dataGridView1[2, i + 3].Value.ToString());
                nowtable1.Cell(i + 3, 5).Range.InsertAfter(dataGridView1[0, i + 3].Value.ToString());
                nowtable1.Cell(i + 3, 6).Range.InsertAfter(dataGridView1[3, i + 3].Value.ToString());
            }

            Microsoft.Office.Interop.Word.Table nowtable2 = wordDoc.Tables[9];//检索表格
            for (int i = 0; i < 26; i++)
            {
                nowtable2.Cell(i + 3, 1).Range.InsertAfter(dataGridView1[0, i + 3].Value.ToString());
                nowtable2.Cell(i + 3, 2).Range.InsertAfter(dataGridView1[4, i + 3].Value.ToString());
                nowtable2.Cell(i + 3, 3).Range.InsertAfter(dataGridView1[0, i + 3].Value.ToString());
                nowtable2.Cell(i + 3, 4).Range.InsertAfter(dataGridView1[5, i + 3].Value.ToString());
                nowtable2.Cell(i + 3, 5).Range.InsertAfter(dataGridView1[0, i + 3].Value.ToString());
                nowtable2.Cell(i + 3, 6).Range.InsertAfter(dataGridView1[6, i + 3].Value.ToString());
            }

            Microsoft.Office.Interop.Word.Table nowtable3 = wordDoc.Tables[10];//检索表格
            for (int i = 0; i < 26; i++)
            {
                nowtable3.Cell(i + 3, 1).Range.InsertAfter(dataGridView1[0, i + 3].Value.ToString());
                nowtable3.Cell(i + 3, 2).Range.InsertAfter(dataGridView1[7, i + 3].Value.ToString());
                nowtable3.Cell(i + 3, 3).Range.InsertAfter(dataGridView1[0, i + 3].Value.ToString());
                nowtable3.Cell(i + 3, 4).Range.InsertAfter(dataGridView1[8, i + 3].Value.ToString());
                nowtable3.Cell(i + 3, 5).Range.InsertAfter(dataGridView1[0, i + 3].Value.ToString());
                nowtable3.Cell(i + 3, 6).Range.InsertAfter(dataGridView1[9, i + 3].Value.ToString());
            }
            wordDoc.Save();
            wordApp.Quit();
            wordApp = null;
        }
コード例 #16
0
        /// <summary>
        /// Закрытие приложения
        /// </summary>
        public void QuitApplication()
        {
            if (application != null)
            {
                range = null;
                table = null;
                document = null;
                application.Quit();
                application = null;                
            }

        }
コード例 #17
0
 private void InitRows(ref Microsoft.Office.Interop.Word.Table tb)
 {
     //todo yyb
     foreach (AssessActivityItem item in _AssessActivity.ItsAssessActivityPaper.ItsAssessActivityItems)
     {
         if (item.Classfication != ItemClassficationEmnu._360)
         {
             _ItemCount++;
         }
     }
     AddNeedRow(ref tb, _ItemCount, 6);
 }
コード例 #18
0
        private void AddEducationInfo(ref Microsoft.Office.Interop.Word.Table tb)
        {
            int i = 0;

            foreach (EducationExperience educationExperience in _Employee.EmployeeDetails.Education.EducationExperiences)
            {
                tb.Cell(_EducationStratRow + i, 1).Range.Text = educationExperience.ExperiencePeriod;
                tb.Cell(_EducationStratRow + i, 2).Range.Text = educationExperience.Place;
                tb.Cell(_EducationStratRow + i, 3).Range.Text = educationExperience.Contect;
                i++;
            }
        }
コード例 #19
0
        public static string GetWordPreview(string strFileName, bool boolVirtual = false, bool afterDelete = false)
        {
            string strPhysicalFilrName = boolVirtual ? HostingEnvironment.MapPath(strFileName) : strFileName;
            string strReturn           = string.Empty;

            if (File.Exists(strPhysicalFilrName))
            {
                object oFileName = strPhysicalFilrName;
                object oReadOnly = true;
                object oMissing  = System.Reflection.Missing.Value;

                Microsoft.Office.Interop.Word._Application oWord;
                Microsoft.Office.Interop.Word._Document    oDoc;
                oWord = new Microsoft.Office.Interop.Word.Application();
                oDoc  = oWord.Documents.Open(ref oFileName, ref oMissing, ref oReadOnly, ref oMissing, ref oMissing,
                                             ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                                             ref oMissing, ref oMissing);
                string tableMessage = string.Empty;
                for (int tablePos = 1; tablePos <= oDoc.Tables.Count; tablePos++)
                {
                    Microsoft.Office.Interop.Word.Table nowTable = oDoc.Tables[tablePos];
                    tableMessage = tableMessage + string.Format("<br/>第{0}/{1}个表:<br/>", tablePos, oDoc.Tables.Count);

                    for (int i = 1; i <= nowTable.Rows.Count; i++)
                    {
                        for (int j = 1; j <= nowTable.Columns.Count; j++)
                        {
                            try
                            {
                                string text = nowTable.Cell(i, j).Range.Text;
                                tableMessage = tableMessage + text;
                                tableMessage = tableMessage.Remove(tableMessage.Length - 2, 2); //remove \r\a
                                tableMessage = tableMessage + "(" + tablePos + "," + i + "," + j + ")";
                                tableMessage = tableMessage + "<br/>";
                            }
                            catch (Exception)
                            {
                                continue;
                            }
                        }
                        tableMessage = tableMessage + "<br/>";
                    }
                }
                strReturn = tableMessage.Replace("\r", "<br/>");
                oDoc.Close();
                oWord.Quit();
                if (afterDelete)
                {
                    File.Delete(strPhysicalFilrName);
                }
            }
            return(strReturn);
        }
コード例 #20
0
        //</Snippet2>


        //---------------------------------------------------------------------
        //<Snippet3>
        private void AddData(System.Data.DataRow row, string companyName)
        {
            object missing = System.Type.Missing;

            // Create a table if it doesn't already exist.
            if (Globals.ThisDocument.Tables.Count == 0)
            {
                try
                {
                    // Create a table.
                    Microsoft.Office.Interop.Word.Table tbl = Globals.ThisDocument.Tables.Add
                                                                  (Globals.ThisDocument.Application.Selection.Range, 1, 4, ref missing, ref missing);

                    // Insert headings.
                    SetHeadings(tbl.Cell(1, 1), "Company Name");
                    SetHeadings(tbl.Cell(1, 2), "Product Name");
                    SetHeadings(tbl.Cell(1, 3), "Quantity");
                    SetHeadings(tbl.Cell(1, 4), "Unit Price");
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Problem creating Products table: " + ex.Message,
                                    "Actions Pane", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            // Add data from data row to the table.
            Microsoft.Office.Interop.Word.Selection selection = Globals.ThisDocument.Application.Selection;

            if (selection.Tables.Count > 0)
            {
                Microsoft.Office.Interop.Word.Row newRow = Globals.ThisDocument.Tables[1].Rows.Add(ref missing);

                newRow.Range.Font.Bold = 0;

                newRow.Range.ParagraphFormat.Alignment =
                    Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;

                newRow.Cells[4].Range.ParagraphFormat.Alignment =
                    Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight;

                newRow.Cells[1].Range.Text = companyName;
                newRow.Cells[2].Range.Text = row["ProductName"].ToString();
                newRow.Cells[3].Range.Text = row["QuantityPerUnit"].ToString();
                newRow.Cells[4].Range.Text = Math.Round(Convert.ToDouble(row["UnitPrice"])).ToString("#,##0.00");
            }
            else
            {
                MessageBox.Show("Cursor must be within a table.",
                                "Actions Pane", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #21
0
ファイル: Form1.cs プロジェクト: radtek/mshan
        public void CreateWordTables(Table userTable, WordHelper wordHelper)
        {
            wordHelper.SetFont(11f);
            Microsoft.Office.Interop.Word.Table wordTable = wordHelper.InsertTable(3, 4, 500);
            SetColumnWidth(wordTable);
            int pointer = 1;

            pointer = TableHeader(userTable, pointer, wordTable);
            pointer = TableColumnName(pointer, wordTable);
            pointer = TableColumns(userTable.Columns, pointer, wordTable);
            pointer = TableIndexes(userTable.Indexes, pointer, wordTable);
            pointer = TableTrigger(userTable.Triggeres, pointer, wordTable);
        }
コード例 #22
0
        /// <summary>
        /// 执行导出方法
        /// </summary>
        /// <returns></returns>
        public string  ExcuteSelf()
        {
            Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();
            object nothing    = Type.Missing;
            object localPatho = _EmployeeTemplateLocation;

            Microsoft.Office.Interop.Word.Document doc = app.Documents.Add(ref localPatho, ref nothing, ref nothing, ref nothing);
            try
            {
                if (!Directory.Exists(_EmployeeExportLocation))
                {
                    Directory.CreateDirectory(_EmployeeExportLocation);
                }
                Microsoft.Office.Interop.Word.Table tb = doc.Tables[1];
                InitRows(ref tb);
                AddBasicInfo(ref tb);
                AddFamilyInfo(ref tb);
                AddWorkInfo(ref tb);
                AddEducationInfo(ref tb);
                AddLanguageInfo(ref tb);
                AddEmployeePhoto(ref tb, ref doc);

                object fileFormat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatTemplate97;
                object filename   = _EmployeeExportLocation + "\\" + _Employee.Account.Name + "的员工信息登记表.doc";
                doc.SaveAs(ref filename, ref fileFormat, 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);
                return(filename.ToString());
            }
            catch (Exception e)
            {
                doc.Tables[1].Cell(3, 2).Range.Text = e.Message;
                object filename   = _EmployeeExportLocation + "\\" + "temp.doc";
                object fileFormat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatTemplate97;
                doc.SaveAs(ref filename, ref fileFormat, 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);
                return("");
            }
            finally
            {
                doc.Close(ref nothing, ref nothing, ref nothing);
                app.Quit(ref nothing, ref nothing, ref nothing);
                //清理照片
                if (File.Exists(_TempPhotolocation))
                {
                    File.Delete(_TempPhotolocation);
                }
            }
        }
コード例 #23
0
        private void AddWorkInfo(ref Microsoft.Office.Interop.Word.Table tb)
        {
            int i = 0;

            foreach (WorkExperience workExperience in _Employee.EmployeeDetails.Work.WorkExperiences)
            {
                tb.Cell(_WorkStartRow + i, 1).Range.Text = workExperience.ExperiencePeriod;
                tb.Cell(_WorkStartRow + i, 2).Range.Text = workExperience.Place;
                tb.Cell(_WorkStartRow + i, 3).Range.Text = workExperience.ContactPerson;
                tb.Cell(_WorkStartRow + i, 4).Range.Text = workExperience.Contect;
                tb.Cell(_WorkStartRow + i, 5).Range.Text = workExperience.Remark;
                i++;
            }
        }
コード例 #24
0
        private void AddFamilyInfo(ref Microsoft.Office.Interop.Word.Table tb)
        {
            int i = 0;

            foreach (FamilyMember familyMember in _Employee.EmployeeDetails.Family.FamilyMembers)
            {
                tb.Cell(_FamilyStartRow + i, 1).Range.Text = familyMember.Name;
                tb.Cell(_FamilyStartRow + i, 2).Range.Text = familyMember.Relationship;
                tb.Cell(_FamilyStartRow + i, 3).Range.Text = familyMember.Age.ToString();
                tb.Cell(_FamilyStartRow + i, 4).Range.Text = familyMember.Company;
                tb.Cell(_FamilyStartRow + i, 5).Range.Text = familyMember.Remark;
                i++;
            }
        }
コード例 #25
0
    private static void _CellsWrite(int[] posRC, Microsoft.Office.Interop.Word.Table myTable, IEnumerable <string> sb)
    {
        int i = 0;

        foreach (string str in sb)
        {
            while (!IsExistRow(myTable, posRC[0] + i))
            {
                myTable.Rows.Add();
            }
            myTable.Cell(posRC[0] + i, posRC[1]).Range.Text = str;
            i += 1;
        }
    }
コード例 #26
0
        private void button4_Click(object sender, EventArgs e)
        {
            #region  除后台word占用。
            System.Diagnostics.Process myproc = new System.Diagnostics.Process();
            //得到所有打开的进程
            try
            {
                foreach (Process thisproc in Process.GetProcessesByName("WINWORD"))
                {
                    if (!thisproc.CloseMainWindow())
                    {
                        thisproc.Kill();
                    }
                }
            }
            catch (Exception)
            {
                MessageBox.Show("杀死" + "WINWORD" + "失败!");
            }
            #endregion
            try
            {
                object filename = Environment.CurrentDirectory.ToString() + "\\bin\\" + Global.templateName;
                Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application();
                Microsoft.Office.Interop.Word.Document    wordDoc;
                wordDoc = wordApp.Documents.Open(filename);
                wordDoc.ActiveWindow.Visible = false;                             //打开word

                Microsoft.Office.Interop.Word.Table nowtable = wordDoc.Tables[3]; //检索表格

                for (int j = 0; j < dataGridView2.ColumnCount - 1; j++)
                {
                    for (int i = 0; i < dataGridView2.RowCount - 1; i++)
                    {
                        nowtable.Cell(i + 2, j + 2).Range.InsertAfter(dataGridView2[j + 1, i].Value.ToString());//填充表格
                    }
                }
                wordDoc.Save();
                wordApp.Quit();
                wordApp = null;

                MessageBox.Show("导入成功。");
            }
            catch (Exception)
            {
                MessageBox.Show("失败。");
            }
        }
コード例 #27
0
        private void InitRows(ref Microsoft.Office.Interop.Word.Table tb)
        {
            _FamilyCount    = _Employee.EmployeeDetails.Family.FamilyMembers.Count;
            _WorkCount      = _Employee.EmployeeDetails.Work.WorkExperiences.Count;
            _EducationCount = _Employee.EmployeeDetails.Education.EducationExperiences.Count;
            _FamilyStartRow = 15;

            _FamilyCount    = _FamilyCount == 0 ? 1 : _FamilyCount;
            _WorkCount      = _WorkCount == 0 ? 1 : _WorkCount;
            _EducationCount = _EducationCount == 0 ? 1 : _EducationCount;

            _WorkStartRow      = _FamilyStartRow + _FamilyCount + 2;
            _EducationStratRow = _WorkStartRow + _WorkCount + 2;
            _LanguageStratRow  = _EducationStratRow + _EducationCount + 1;
            AddNeedRow(ref tb, _FamilyCount, _FamilyStartRow);
            AddNeedRow(ref tb, _WorkCount, _WorkStartRow);
            AddNeedRow(ref tb, _EducationCount, _EducationStratRow);
        }
コード例 #28
0
        /// <summary>
        /// 导出Word 的方法
        /// </summary>
        private void tslExport_Word()
        {
            SaveFileDialog sfile = new SaveFileDialog();

            sfile.AddExtension = true;
            sfile.DefaultExt   = ".doc";
            sfile.Filter       = "(*.doc)|*.doc";
            sfile.FileName     = "理文检测系统抽包统计Word报表" + DateTime.Now.ToShortDateString();
            if (sfile.ShowDialog() == DialogResult.OK)
            {
                object path = sfile.FileName;
                Object none = System.Reflection.Missing.Value;
                Microsoft.Office.Interop.Word.Application wordApp  = new Microsoft.Office.Interop.Word.Application();
                Microsoft.Office.Interop.Word.Document    document = wordApp.Documents.Add(ref none, ref none, ref none, ref none);
                //建立表格
                Microsoft.Office.Interop.Word.Table table = document.Tables.Add(document.Paragraphs.Last.Range, lvwUserList.Rows.Count + 1, lvwUserList.Columns.Count, ref none, ref none);
                try
                {
                    for (int i = 0; i < lvwUserList.Columns.Count; i++)//设置标题
                    {
                        table.Cell(0, i + 1).Range.Text = lvwUserList.Columns[i].HeaderText;
                    }
                    for (int i = 1; i < lvwUserList.Rows.Count; i++)//填充数据
                    {
                        for (int j = 0; j < lvwUserList.Columns.Count; j++)
                        {
                            //table.Cell(i + 1, j + 1).Range.Text = dgvCarStatisticsQC[j, i - 1].Value.ToString();
                            if (lvwUserList[j, i - 1].Value != null)
                            {
                                table.Cell(i + 1, j + 1).Range.Text = lvwUserList[j, i - 1].Value.ToString();
                            }
                        }
                    }
                    document.SaveAs(ref path, ref none, ref none, ref none, ref none, ref none, ref none, ref none, ref none, ref none, ref none, ref none, ref none, ref none, ref none, ref none);
                    document.Close(ref none, ref none, ref none);
                    MessageBox.Show("导出数据成功!");
                }

                finally
                {
                    wordApp.Quit(ref none, ref none, ref none);
                }
            }
        }
コード例 #29
0
        private void ExportAssessSystemInfo(ref Microsoft.Office.Interop.Word.Table tb)
        {
            decimal grade = 0;

            for (int i = 0; i < _ItemCount; i++)
            {
                //todo yyb
                AssessActivityItem managerItem = _AssessActivity.ItsAssessActivityPaper.ItsAssessActivityItems[i];
                if (managerItem.Classfication == ItemClassficationEmnu._360)
                {
                    continue;
                }
                tb.Cell(6 + i, 1).Range.Text =
                    AssessSystemUtility.GetItemClassficationNameByItemClassfication(managerItem.Classfication);
                string questionAndNote = managerItem.Question;
                if (!string.IsNullOrEmpty(managerItem.Note))
                {
                    questionAndNote += "(" + managerItem.Note + ")";
                }
                if (managerItem.AssessTemplateItemType == AssessTemplateItemType.Option)
                {
                    tb.Cell(6 + i, 2).Range.Text = questionAndNote;
                    //如果不是1到5分将存在问题
                    string[] options        = managerItem.Option.Split('/');
                    int      gradecellindex = managerItem.Grade < 6 ? Decimal.ToInt32(managerItem.Grade) : Decimal.ToInt32(managerItem.Grade) / 20;

                    tb.Cell(6 + i, 3).Range.Text = options[5 - gradecellindex];
                    tb.Cell(6 + i, 4).Range.Text = (managerItem.Grade * managerItem.Weight).ToString();
                }
                else if (managerItem.AssessTemplateItemType == AssessTemplateItemType.Open)
                {
                    tb.Cell(6 + i, 2).Range.Text = managerItem.Question;
                    tb.Cell(6 + i, 3).Range.Text = managerItem.Note;
                    tb.Cell(6 + i, 4).Range.Text = "不计分";
                }
                else
                {
                    tb.Cell(6 + i, 2).Range.Text = questionAndNote;
                    tb.Cell(6 + i, 4).Range.Text = (managerItem.Grade * managerItem.Weight).ToString();
                }
                grade += (managerItem.Grade * managerItem.Weight);
            }
            tb.Cell(6 + _ItemCount, 4).Range.Text = grade.ToString();
        }
コード例 #30
0
        public string  Addsupervisordata(WordTableInfo Info)
        {
            Common.Common.load_supervisor();
            object missingValue = System.Reflection.Missing.Value;
            object myTrue       = false;            //不显示Word窗口
            //object fileName = Environment.CurrentDirectory + "\\" + "chief_supervisor.doc";
            object fileName1 = Environment.CurrentDirectory + "\\" + "supervisor.doc";
            string newfile   = Common.Common.strAddfilesPath + "\\" + Info.Teacher + Info.Time.Trim() + Info.Supervisor + ".doc";

            Microsoft.Office.Interop.Word._Application oWord1 = new Microsoft.Office.Interop.Word.Application();
            Microsoft.Office.Interop.Word._Document    oDoc1;
            oDoc1 = oWord1.Documents.Open(ref fileName1, ref missingValue,
                                          ref myTrue, ref missingValue, ref missingValue, ref missingValue,
                                          ref missingValue, ref missingValue, ref missingValue,
                                          ref missingValue, ref missingValue, ref missingValue,
                                          ref missingValue, ref missingValue, ref missingValue,
                                          ref missingValue);
            Microsoft.Office.Interop.Word.Table newtable1 = oDoc1.Tables[1];
            oWord1.Selection.TypeText("广东医学院教师课堂教学质量评价表" + "(" + Info.Teachingtype + ")");
            newtable1.Cell(1, 2).Range.Text = Info.Teacher;
            newtable1.Cell(1, 4).Range.Text = Info.Perfession;
            newtable1.Cell(1, 6).Range.Text = Info.Time.Substring(0, Info.Time.IndexOf(" "));
            newtable1.Cell(2, 2).Range.Text = Info.Class;
            newtable1.Cell(2, 4).Range.Text = Info.Classroom + Info.Time.Substring(Info.Time.IndexOf(" ") + 1);
            newtable1.Cell(3, 2).Range.Text = Info.Subject;
            object bSaveChange = true;

            oDoc1.Close(ref bSaveChange, ref missingValue, ref missingValue);
            oDoc1  = null;
            oWord1 = null;



            closefile();
            if (!System.IO.File.Exists(Common.Common.strAddfilesPath))
            {
                Directory.CreateDirectory(Common.Common.strAddfilesPath);
            }
            System.IO.File.Copy(fileName1.ToString(), newfile, true);

            File.Delete(fileName1.ToString());
            return(newfile);
        }
コード例 #31
0
        // Запись в Word
        public static void ZapisWordIsx(int length, int[] mas, string title)
        {
            Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();
            var Wrd = new Microsoft.Office.Interop.Word.Application();

            Wrd.Visible = true;
            var    inf = Type.Missing;
            String str;
            var    Doc = Wrd.Documents.Add(inf, inf, inf, inf); Wrd.Selection.TypeText(title);
            Object t1  = Microsoft.Office.Interop.Word.WdDefaultTableBehavior.wdWord9TableBehavior;
            Object t2  = Microsoft.Office.Interop.Word.WdAutoFitBehavior.wdAutoFitContent;

            Microsoft.Office.Interop.Word.Table tbl = Wrd.ActiveDocument.Tables.Add(Wrd.Selection.Range, 2, length, t1, t2);
            for (int i = 0; i < length; i++)
            {
                tbl.Cell(1, i + 1).Range.InsertAfter("[" + Convert.ToString(i) + "]");
                str = String.Format("{0:f0}", mas[i]); tbl.Cell(2, i + 1).Range.InsertAfter(str);
            }
        }
コード例 #32
0
 /// <summary>
 /// Находим таблицу со строкой
 /// </summary>
 /// <param name="parString">Параметр - строка</param>
 public void GetTableWithString(String parString)
 {
     String st = String.Empty;
     int i = 1;
     do
     {
         table = document.Tables[i];
         st = table.Cell(1, 1).Range.Text;
         i++;
     }
     while (!st.Contains("№"));
 }
コード例 #33
0
ファイル: TableProcessor.cs プロジェクト: PAlAl/ImportMStoDB
 /// <summary>
 /// Контруктор для класса
 /// </summary>
 /// <param name="parTable">Таблица для обработки</param>
 public TableProcessor(Interpop.Word.Table parTable)
 {
     this.table = parTable;
     ProcessingTable();
 }