/// <summary>
        /// insert standard job information to test report (work order number, test condition, part number, date code)
        /// </summary>
        public void Set_Job_Info(string structureTitle = "")
        {
            try
            {
                WordApp.Selection.Find.Execute("<wo number>", true, true, false, false, false, true, 1, false, WorkOrderNumber, 2, false, false, false, false);
                WordApp.Selection.Find.Execute("<condition>", true, true, false, false, false, true, 1, false, TestCondition, 2, false, false, false, false);
                WordApp.Selection.Find.Execute("<part number>", true, true, false, false, false, true, 1, false, PartNumber, 2, false, false, false, false);
                WordApp.Selection.Find.Execute("<date code>", true, true, false, false, false, true, 1, false, DateCode, 2, false, false, false, false);
                WordApp.Selection.Find.Execute("<structure title>", true, true, false, false, false, true, 1, false, structureTitle, 2, false, false, false, false);
            }
            catch (Exception err)
            {
                sw = new StreamWriter(ErrorLogFilePath, true);
                sw.WriteLine($"{DateTime.Now.ToShortTimeString()}\nReport Set_Job_Info -- {err.Source}; {err.TargetSite}\n{err.Message}\n");
                sw.Close();

                if (WordDoc != null)
                {
                    WordDoc.Close(Word.WdSaveOptions.wdDoNotSaveChanges, Word.WdOriginalFormat.wdOriginalDocumentFormat, false);
                }
                if (WordApp != null)
                {
                    WordApp.Quit();
                }
                throw;
            }
        }
Example #2
0
        static Texto TestComment(WordDoc wordDoc)
        {
            Comentario comentario = wordDoc.CreateComment();

            comentario.Append(
                "Descrição do comentário",
                new RunProperties()
            {
                Caps = new Caps()
                {
                    Val = OnOffValue.FromBoolean(true)
                }
            }
                );

            Texto texto = new Texto();

            texto.Append("Aqui vai começar um comentário, ");
            texto.StartComment(comentario.Id);
            texto.Append(
                "Texto de comentário, ",
                new RunProperties()
            {
                Bold = new Bold()
                {
                    Val = OnOffValue.FromBoolean(true)
                }
            }
                );
            texto.EndComment(comentario.Id);
            texto.Append("Texto fora do comentário,");

            return(texto);
        }
        public void SetHeaderInfo(List <string> headerInfo)
        {
            try
            {
                //string dateTested = headerInfo[0].ToString() == "" ? "" : ((DateTime)headerInfo[0]).ToShortDateString();
                WordDoc.Sections[1].Headers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Find.Execute("<date tested>", true, true, false, false, false, true, 1, false, headerInfo[0], 2, false, false, false, false);
                WordDoc.Sections[1].Headers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Find.Execute("<tested by>", true, true, false, false, false, true, 1, false, headerInfo[1], 2, false, false, false, false);
                WordDoc.Sections[1].Headers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Find.Execute("<check by>", true, true, false, false, false, true, 1, false, headerInfo[2], 2, false, false, false, false);
            }
            catch (Exception err)
            {
                sw = new StreamWriter(ErrorLogFilePath, true);
                sw.WriteLine($"{DateTime.Now.ToShortTimeString()}\nHardCopy Set_Header_Info -- {err.Source}; {err.TargetSite}\n{err.Message}\n");
                sw.Close();

                if (WordDoc != null)
                {
                    WordDoc.Close(Word.WdSaveOptions.wdDoNotSaveChanges, Word.WdOriginalFormat.wdOriginalDocumentFormat, false);
                }
                if (WordApp != null)
                {
                    WordApp.Quit();
                }
                throw;
            }
        }
        public HardCopy(string workOrderNumber, string testCondition, string testPerformedOn)
        {
            WorkOrderNumber  = workOrderNumber;
            TestCondition    = testCondition;
            TestConditionAbr = testCondition == "As Received" ? "AR" : "TS";
            TestPerformedOn  = testPerformedOn;

            try
            {
                WordApp = new Word.Application();
                //WordApp.Visible = true;
                string path = testCondition == "As Received" ? @"hard_copy_location\Digital Datasheet Forms\AR_datasheet_template.docx" : @"hard_copy_location\Digital Datasheet Forms\TS_datasheet_template.docx";
                //string path = testCondition == "As Received" ? @"C:\Users\Nicholas\Documents\PTL\AR_datasheet_template.docx" : @"C:\Users\Nicholas\Documents\PTL\TS_datasheet_template.docx";
                WordDoc = WordApp.Documents.Open(path, true, true);
            }
            catch (Exception err)
            {
                sw = new StreamWriter(ErrorLogFilePath, true);
                sw.WriteLine($"{DateTime.Now.ToShortTimeString()}\nHardCopy constructor -- {err.Source}; {err.TargetSite}\n{err.Message}\n");
                sw.Close();

                if (WordDoc != null)
                {
                    WordDoc.Close(Word.WdSaveOptions.wdDoNotSaveChanges, Word.WdOriginalFormat.wdOriginalDocumentFormat, false);
                }
                if (WordApp != null)
                {
                    WordApp.Quit();
                }
                throw;
            }
        }
Example #5
0
        /// <summary>
        /// 分离单元格
        /// </summary>
        public static void SeparateCell()
        {
            object oMissing = System.Reflection.Missing.Value;

            Microsoft.Office.Interop.Word._Application WordApp;
            Microsoft.Office.Interop.Word._Document    WordDoc;
            WordApp         = new Microsoft.Office.Interop.Word.Application();
            WordApp.Visible = true;
            WordDoc         = WordApp.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);

            object start = 0;
            object end   = 0;

            Microsoft.Office.Interop.Word.Range tableLocation = WordDoc.Range(ref start, ref end);
            WordDoc.Tables.Add(tableLocation, 3, 4, ref oMissing, ref oMissing);

            Microsoft.Office.Interop.Word.Table newTable = WordDoc.Tables[1];
            object beforeRow = newTable.Rows[1];

            newTable.Rows.Add(ref beforeRow);

            Microsoft.Office.Interop.Word.Cell cell = newTable.Cell(1, 1);
            cell.Merge(newTable.Cell(1, 2));

            object Rownum    = 2;
            object Columnnum = 2;

            cell.Split(ref Rownum, ref Columnnum);
        }
Example #6
0
        /// <summary>
        /// 添加到文档
        /// </summary>
        /// <param name="srcDoc"></param>
        /// <param name="includeSection"></param>
        public void appendDoc(Document srcDoc, bool includeSection)
        {
            // Loop through all sections in the source document.
            // Section nodes are immediate children of the Document node so we can
            // just enumerate the Document.
            if (includeSection)
            {
                foreach (Section srcSection in srcDoc.Sections)
                {
                    Node dstNode = WordDoc.ImportNode(srcSection, true, ImportFormatMode.UseDestinationStyles);
                    WordDoc.AppendChild(dstNode);
                }
            }
            else
            {
                //find the last paragraph of the last section
                Node node = WordDoc.LastSection.Body.LastParagraph;

                if (node == null)
                {
                    node = new Paragraph(srcDoc);
                    WordDoc.LastSection.Body.AppendChild(node);
                }

                if ((node.NodeType != NodeType.Paragraph)
                    & (node.NodeType != NodeType.Table))
                {
                    throw new Exception("Use appendDoc(dstDoc, srcDoc, true) instead of appendDoc(dstDoc, srcDoc, false)");
                }
                insertDocumentAfterNode(node, srcDoc);
            }
        }
Example #7
0
        private void button5_Click(object sender, EventArgs e)
        {
            Word.Document WordDoc;
            var           WordApp = new Word.Application();

            WordApp.Visible = true;
            WordDoc         = WordApp.Documents.Add(Type.Missing, false, Word.WdNewDocumentType.wdNewBlankDocument, true);
            Word.Range wordrange = WordDoc.Range(0, 0);
            Word.Table wordtable = WordDoc.Tables.Add(wordrange, dataGridView1.RowCount, dataGridView1.ColumnCount, Word.WdDefaultTableBehavior.wdWord9TableBehavior, Word.WdAutoFitBehavior.wdAutoFitWindow);

            Word.Range wordcellrange = WordDoc.Tables[1].Cell(1, 1).Range;
            wordcellrange.Text = "№";
            wordcellrange      = wordtable.Cell(1, 2).Range;
            wordcellrange.Text = "Классификатор";
            wordcellrange      = wordtable.Cell(1, 3).Range;
            wordcellrange.Text = "Диагноз";
            wordcellrange      = wordtable.Cell(1, 4).Range;
            wordcellrange.Text = "Стоимость лечения";

            for (int m = 1; m < wordtable.Rows.Count; m++)
            {
                for (int n = 0; n < wordtable.Columns.Count; n++)
                {
                    wordcellrange      = wordtable.Cell(m + 1, n + 1).Range;
                    wordcellrange.Text = dataGridView1[n, m - 1].Value.ToString();
                }
            }
        }
Example #8
0
        /// <summary>
        /// 合并单元格
        /// </summary>
        public static void CombinationCell()
        {
            object oMissing = System.Reflection.Missing.Value;

            Microsoft.Office.Interop.Word._Application WordApp;
            Microsoft.Office.Interop.Word._Document    WordDoc;
            WordApp         = new Microsoft.Office.Interop.Word.Application();
            WordApp.Visible = true;
            WordDoc         = WordApp.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);

            object start = 0;
            object end   = 0;

            Microsoft.Office.Interop.Word.Range tableLocation = WordDoc.Range(ref start, ref end);
            WordDoc.Tables.Add(tableLocation, 3, 4, ref oMissing, ref oMissing);

            Microsoft.Office.Interop.Word.Table newTable = WordDoc.Tables[1];
            object beforeRow = newTable.Rows[1];

            newTable.Rows.Add(ref beforeRow);

            Microsoft.Office.Interop.Word.Cell cell = newTable.Cell(2, 1);//2行1列合并2行2列为一起
            cell.Merge(newTable.Cell(2, 2));
            //cell.Merge( newTable.Cell( 1, 3 ) );
        }
Example #9
0
        /// <summary>
        /// 获取word 无格式的text文本
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static string WordToText(string path)
        {
            string wordText = "";

            Microsoft.Office.Interop.Word.Application WordApp = new Microsoft.Office.Interop.Word.Application();//ApplicationClass();
            Microsoft.Office.Interop.Word.Document    WordDoc;
            Microsoft.Office.Interop.Word.Documents   docs = WordApp.Documents;

            Object oMissing = System.Reflection.Missing.Value;
            Type   wordType = WordApp.GetType();

            object fileName = path;

            WordDoc = WordApp.Documents.Open(ref fileName,
                                             ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                                             ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                                             ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);

            wordText = WordDoc.Content.Text;

            WordDoc.Close(ref oMissing, ref oMissing, ref oMissing);
            WordApp.Quit(ref oMissing, ref oMissing, ref oMissing);
            GC.Collect();

            return(wordText);
        }
Example #10
0
        public static void WordToHtml(string sourceFileName, string targetFileName)
        {
            Microsoft.Office.Interop.Word.ApplicationClass WordApp;
            Microsoft.Office.Interop.Word.Document         WordDoc;
            Object oMissing = System.Reflection.Missing.Value;

            WordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
            object fileName = sourceFileName;

            WordDoc = WordApp.Documents.Open(ref fileName,
                                             ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                                             ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                                             ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
            try
            {
                Type wordType = WordApp.GetType();
                // 打开文件
                Type docsType = WordApp.Documents.GetType();
                // 转换格式,另存为
                Type   docType      = WordDoc.GetType();
                object saveFileName = targetFileName;
                docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod, null, WordDoc, new object[] { saveFileName, Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatHTML });
            }
            finally
            {
                WordDoc.Close(ref oMissing, ref oMissing, ref oMissing);
                WordApp.Quit(ref oMissing, ref oMissing, ref oMissing);
            }
        }
Example #11
0
        private void btnPrint_Click(object sender, EventArgs e)
        {
            try
            {
                WordDoc wd = new WordDoc(string.Format(@"{0}\ListPerson.dot", MainClass.dirTemplates));

                int k = dgvAbiturients.Columns.Count;
                wd.AddNewTable(dgvAbiturients.Rows.Count + 1, k);
                TableDoc td = wd.Tables[0];

                int?   facId = ComboServ.GetComboIdInt(cbFaculty);
                string sFac  = cbFaculty.Text.ToLower();
                if (sFac.CompareTo("все") == 0)
                {
                    sFac = "";
                }
                else
                {
                    sFac = "получивших направления на послеление от ";
                    if (facId == 3)
                    {
                        sFac += "высшей школы менеджмента ";
                    }
                    else
                    {
                        sFac += sFac.Replace("кий", "кого ").Replace("ый", "ого ") + " факультета ";
                    }
                }

                wd.Fields["Faculty"].Text = sFac;
                wd.Fields["Info"].Text    = "для общежитий";


                int i = 0;

                td[0, 0] = "№ п/п";
                for (int j = 0; j < k - 1; j++)
                {
                    td[j + 1, 0] = dgvAbiturients.Columns[j + 1].HeaderText;
                }

                // печать из грида
                foreach (DataGridViewRow dgvr in dgvAbiturients.Rows)
                {
                    td[0, i + 1] = (i + 1).ToString();
                    for (int j = 0; j < k - 1; j++)
                    {
                        td[j + 1, i + 1] = dgvAbiturients.Rows[i].Cells[j + 1].Value.ToString();
                    }

                    i++;
                }
            }
            catch (Exception exc)
            {
                WinFormsServ.Error("Ошибка вывода в Word: \n" + exc.Message);
            }
        }
Example #12
0
        //предварительный просмотр
        protected override void Preview()
        {
            try
            {
                WordDoc wd = new WordDoc(string.Format(@"{0}\EmptyTemplate.dot", MainClass.dirTemplates));

                int counter = 0;

                int lstCount      = -1;
                int lstTableCount = 0;
                //foreach (List<string> lst in lstSelected.Values)
                foreach (int?key in lstSelected.Keys)
                {
                    List <string> lst = lstSelected[key];

                    lstCount++;
                    if (lst.Count == 0)
                    {
                        continue;
                    }

                    string header = MainClass.Bdc.GetStringValue("SELECT Name FROM ed.EntryHeader WHERE id=" + key);
                    wd.AddParagraph(string.Format("\r\n {0}", header));
                    wd.AddNewTable(lst.Count + 1, 6);
                    TableDoc td = wd.Tables[lstTableCount];
                    ++lstTableCount;
                    //заполняем таблицу в шаблоне

                    int r = 0;

                    td[0, r] = "№ п/п";
                    td[1, r] = "Рег.номер";
                    td[2, r] = "ФАМИЛИЯ, ИМЯ, ОТЧЕСТВО";
                    td[3, r] = "Сумма баллов";
                    td[4, r] = "Направление или Направление (профиль или Профиль)";
                    td[5, r] = "Вид конкурса";

                    DataSet ds = MainClass.Bdc.GetDataSet(sQuery + string.Format(" WHERE ed.qAbiturientId IN ({0})", Util.BuildStringWithCollection(lst)) + sOrderby);
                    foreach (DataRow row in ds.Tables[0].Rows)
                    {
                        ++r;
                        ++counter;
                        td[0, r] = counter.ToString();
                        td[1, r] = row["Рег_Номер"].ToString();
                        td[2, r] = row["ФИО"].ToString();
                        td[3, r] = row["Sum"].ToString();
                        td[4, r] = row["Направление"].ToString();
                        td[5, r] = row["Конкурс"].ToString();
                    }
                }
            }
            catch (Exception ex)
            {
                WinFormsServ.Error("Ошибка при выводе в Word протокола о допуске: " + ex.Message);
            }
        }
Example #13
0
        private void btnPrint_Click(object sender, EventArgs e)
        {
            List <string> columnList = new List <string>();

            foreach (DataGridViewColumn column in dgvAbitList.Columns)
            {
                if (column.Visible)
                {
                    columnList.Add(column.Name);
                }
            }

            try
            {
                WordDoc wd = new WordDoc(string.Format(@"{0}\Templates\ListAbit.dot", Application.StartupPath));

                wd.AddNewTable(dgvAbitList.Rows.Count + 1, columnList.Count + 1);
                TableDoc td = wd.Tables[0];

                //переменные
                int?   FacId = ComboServ.GetComboIdInt(cbFaculty);
                string sFac  = cbFaculty.Text;
                if (cbFaculty.Text == ComboServ.DISPLAY_ALL_VALUE)
                {
                    sFac = "Все факультеты";
                }

                wd.Fields["Faculty"].Text = sFac;
                //wd.Fields["Section"].Text = sForm;

                int i = 0;

                td[0, 0] = "№ п/п";
                for (int j = 0; j < columnList.Count; j++)
                {
                    td[j + 1, 0] = dgvAbitList.Columns[columnList[j]].HeaderText;
                }

                // печать из грида
                foreach (DataGridViewRow dgvr in dgvAbitList.Rows)
                {
                    td[0, i + 1] = (i + 1).ToString();
                    for (int j = 0; j < columnList.Count; j++)
                    {
                        td[j + 1, i + 1] = dgvAbitList.Rows[i].Cells[columnList[j]].Value.ToString();
                    }

                    i++;
                }
            }
            catch (Exception exc)
            {
                WinFormsServ.Error("Ошибка вывода в Word: \n" + exc.Message);
            }
        }
 public void AddToIndex(string key, int docId)
 {
     AddWord(key);
     if (!Context.WordDocs.Any(wd => wd.WordId.Equals(key) && wd.DocId == docId))
     {
         WordDoc wordDoc = new WordDoc {
             DocId = docId, WordId = key
         };
         Context.WordDocs.Add(wordDoc);
     }
 }
Example #15
0
 private void btnWord_Click(object sender, EventArgs e)
 {
     try
     {
         WordDoc doc = new WordDoc(MainClass.dirTemplates + "\\Form2.dot", true);
         doc.SetFields("", tbKCP_1kurs.Text);
     }
     catch
     {
     }
 }
Example #16
0
        //печать
        private void btnPrint_Click(object sender, EventArgs e)
        {
            if (ExamVedId == null)
            {
                return;
            }

            try
            {
                WordDoc  wd = new WordDoc(string.Format(@"{0}\Templates\CryptoExamsVed.dot", Application.StartupPath));
                TableDoc td = wd.Tables[0];

                using (PriemEntities context = new PriemEntities())
                {
                    extExamsVed ved = (from ev in context.extExamsVed
                                       where ev.Id == ExamVedId
                                       select ev).FirstOrDefault();

                    wd.Fields["Faculty"].Text    = cbFaculty.Text.ToLower();
                    wd.Fields["Exam"].Text       = ved.ExamName;
                    wd.Fields["StudyBasis"].Text = Util.ToStr(ved.StudyBasisId == null ? "все" : ved.StudyBasisName);
                    wd.Fields["Date"].Text       = ved.Date.ToShortDateString();
                    wd.Fields["VedNum"].Text     = ved.Number.ToString();

                    int i = 1;

                    // печать из грида
                    foreach (DataGridViewRow dgvr in dgvList.Rows)
                    {
                        td[0, i] = i.ToString();
                        td[1, i] = dgvr.Cells["Фамилия"].Value.ToString();
                        td[2, i] = dgvr.Cells["Имя"].Value.ToString();
                        td[3, i] = dgvr.Cells["Отчество"].Value.ToString();
                        td[4, i] = DateTime.Parse(dgvr.Cells["Дата_рождения"].Value.ToString()).ToShortDateString();
                        td[5, i] = dgvr.Cells["Ид_номер"].Value.ToString();
                        td[6, i] = FacultyId.ToString();
                        td[7, i] = ved.ExamName;
                        td[8, i] = ved.ExamId.ToString();
                        td[9, i] = ved.Date.ToShortDateString();;

                        td.AddRow(1);
                        i++;
                    }

                    td.DeleteLastRow();
                }
            }
            catch (Exception exc)
            {
                WinFormsServ.Error("Ошибка вывода в Word: \n" + exc.Message);
            }
        }
        public void Close_Document()
        {
            // save updated document to correct work order number directory

            // setup options for closing original template document
            object saveOption     = Word.WdSaveOptions.wdDoNotSaveChanges;
            object originalFormat = Word.WdOriginalFormat.wdOriginalDocumentFormat;
            object routeDocument  = false;

            // close original template document without saving changes and quit the word app
            WordDoc.Close(saveOption, originalFormat, routeDocument);
            WordApp.Quit();
        }
Example #18
0
        private void btnView_Click(object sender, EventArgs e)
        {
            try
            {
                WordDoc wd = new WordDoc(string.Format(@"{0}\Templates\EmptyTemplate.dot", Application.StartupPath));

                int colCount = 0;
                foreach (DataGridViewColumn clm in dgvMarks.Columns)
                {
                    if (clm.Visible)
                    {
                        colCount++;
                    }
                }

                wd.AddNewTable(2, colCount);
                TableDoc td = wd.Tables[0];

                // печать из грида
                int i = 0;
                foreach (DataGridViewColumn clm in dgvMarks.Columns)
                {
                    if (clm.Visible)
                    {
                        td[i, 0] = clm.HeaderText;
                        i++;
                    }
                }

                i = 1;
                int j;
                foreach (DataGridViewRow dgvr in dgvMarks.Rows)
                {
                    j = 0;
                    foreach (DataGridViewColumn clm in dgvMarks.Columns)
                    {
                        if (clm.Visible)
                        {
                            td[j, i] = dgvr.Cells[clm.Index].Value.ToString();
                            j++;
                        }
                    }
                    i++;
                    td.AddRow(1);
                }
            }
            catch (Exception exc)
            {
                WinFormsServ.Error("Ошибка вывода в Word: \n" + exc.Message);
            }
        }
Example #19
0
        private void btnDocMake_Click(object sender, EventArgs e)
        {
            string currentPath = Directory.GetParent(path).FullName;

            Word.Application WordApp;
            Word.Document    WordDoc;
            WordApp = new Word.Application();
            WordDoc = WordApp.Documents.Open(path);

            ReplaceWord("{name}", name, WordDoc);
            ReplaceWord("{age}", age, WordDoc);
            ReplaceWord("{date}", date, WordDoc);
            WordDoc.SaveAs(currentPath + @"/result.docx");
            WordApp.Visible = true;
        }
Example #20
0
        /// <summary>
        /// word中添加新表
        /// </summary>
        public static void AddTable()
        {
            object oMissing = System.Reflection.Missing.Value;

            Microsoft.Office.Interop.Word._Application WordApp;
            Microsoft.Office.Interop.Word._Document    WordDoc;
            WordApp         = new Microsoft.Office.Interop.Word.Application();
            WordApp.Visible = true;
            WordDoc         = WordApp.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);

            object start = 0;
            object end   = 0;

            Microsoft.Office.Interop.Word.Range tableLocation = WordDoc.Range(ref start, ref end);
            WordDoc.Tables.Add(tableLocation, 3, 4, ref oMissing, ref oMissing);//3行4列的表
        }
Example #21
0
        public void RevisionTest()
        {
            string  rev     = "60";
            var     fixture = new FixtureUtil();
            WordDoc doc     = new WordDoc(fixture.WordSample);
            var     state   = doc.Inspect();
            string  initial = (string)state.Revision.Value;

            Assert.AreEqual("4", initial);

            state.Revision.Value = rev;
            var    targetDoc = doc.Process(state, fixture.ProcessingDir);
            string result    = (string)targetDoc.Inspect().Revision.Value;

            Assert.AreEqual(rev, result);
        }
Example #22
0
        public void EffectiveDateTest()
        {
            string  effDate = "2020-04-12";
            var     fixture = new FixtureUtil();
            WordDoc doc     = new WordDoc(fixture.WordSample);
            var     state   = doc.Inspect();
            string  initial = (string)state.EffectiveDate.Value;

            Assert.AreEqual("2019-11-05", initial);

            state.EffectiveDate.Value = effDate;
            var    targetDoc = doc.Process(state, fixture.ProcessingDir);
            string result    = (string)targetDoc.Inspect().EffectiveDate.Value;

            Assert.AreEqual(effDate, result);
        }
Example #23
0
        private void button5_Click(object sender, EventArgs e)
        {
            Word.Document WordDoc;
            var           WordApp = new Word.Application();

            WordApp.Visible = true;
            //object template = Type.Missing;
            //object newTemplate = false;
            //object documentType = Word.WdNewDocumentType.wdNewBlankDocument;
            //object visible = true;
            WordDoc = WordApp.Documents.Add(Type.Missing, false, Word.WdNewDocumentType.wdNewBlankDocument, true);
            //object start = 0;
            //object end = 0;
            Word.Range wordrange            = WordDoc.Range(0, 0);
            object     defaultTableBehavior = Word.WdDefaultTableBehavior.wdWord9TableBehavior;
            object     autoFitBehavior      = Word.WdAutoFitBehavior.wdAutoFitWindow;

            Word.Table wordtable = WordDoc.Tables.Add(wordrange, dataGridView1.RowCount, dataGridView1.ColumnCount, ref defaultTableBehavior, ref autoFitBehavior);

            Word.Range wordcellrange = WordDoc.Tables[1].Cell(1, 1).Range;
            wordcellrange.Text = "№";
            wordcellrange      = wordtable.Cell(1, 2).Range;
            wordcellrange.Text = "Фамилия";
            wordcellrange      = wordtable.Cell(1, 3).Range;
            wordcellrange.Text = "Имя";
            wordcellrange      = wordtable.Cell(1, 4).Range;
            wordcellrange.Text = "Отчество";
            wordcellrange      = wordtable.Cell(1, 5).Range;
            wordcellrange.Text = "Должность";
            wordcellrange      = wordtable.Cell(1, 6).Range;
            wordcellrange.Text = "Дата рождения";
            wordcellrange      = wordtable.Cell(1, 7).Range;
            wordcellrange.Text = "Дата приема на работу";
            wordcellrange      = wordtable.Cell(1, 8).Range;
            wordcellrange.Text = "Номер кабинета";

            for (int m = 1; m < wordtable.Rows.Count; m++)
            {
                for (int n = 0; n < wordtable.Columns.Count; n++)
                {
                    wordcellrange      = wordtable.Cell(m + 1, n + 1).Range;
                    wordcellrange.Text = dataGridView1[n, m - 1].Value.ToString();
                }
            }
        }
        public void Underline_Serial_Number_Titles()
        {
            try
            {
                for (int i = 2; i <= WordDoc.Tables.Count; i += 2)
                {
                    var table = WordDoc.Tables[i];
                    int row   = 2;
                    for (int j = 0; j < 2; j++)
                    {
                        Word.Cell cell      = table.Cell(row, 1);
                        int       wordCount = cell.Range.Words.Count;
                        for (int k = 1; k < wordCount; k++)
                        {
                            if (cell.Range.Words[k].Text == "S" && cell.Range.Words[k + 1].Text == "/")
                            {
                                while (cell.Range.Words[k].Text != "\r" && k != wordCount)
                                {
                                    cell.Range.Words[k++].Font.Underline = Word.WdUnderline.wdUnderlineSingle;
                                }
                            }
                        }
                        row = 5;
                    }
                }
            }
            catch (Exception err)
            {
                sw = new StreamWriter(ErrorLogFilePath, true);
                sw.WriteLine($"{DateTime.Now.ToShortTimeString()}\nReport Underline_Serial_Number_Titles -- {err.Source}; {err.TargetSite}\n{err.Message}\n");
                sw.Close();

                if (WordDoc != null)
                {
                    WordDoc.Close(Word.WdSaveOptions.wdDoNotSaveChanges, Word.WdOriginalFormat.wdOriginalDocumentFormat, false);
                }
                if (WordApp != null)
                {
                    WordApp.Quit();
                }
                throw;
            }
        }
Example #25
0
        //предварительный просмотр
        protected virtual void Preview()
        {
            if (dgvLeft.Rows.Count == 0)
            {
                MessageBox.Show("Протокол пуст", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            try
            {
                WordDoc wd = new WordDoc(string.Format(@"{0}\EmptyTemplate.dot", MainClass.dirTemplates));
                wd.AddNewTable(dgvLeft.Rows.Count + 1, 7);
                TableDoc td = wd.Tables[0];
                //заполняем таблицу в шаблоне

                int r = 0;

                td[0, r] = "№ п/п";
                td[1, r] = "Рег.номер";
                td[2, r] = "ФАМИЛИЯ, ИМЯ, ОТЧЕСТВО";
                td[3, r] = "Номер документа об образовании";
                td[4, r] = "Направление(профиль)";
                td[5, r] = "Вид конкурса";
                td[6, r] = "Номер и серия паспорта";

                foreach (DataGridViewRow row in dgvLeft.Rows)
                {
                    ++r;
                    td[0, r] = r.ToString();
                    td[1, r] = row.Cells["Num"].Value.ToString();
                    td[2, r] = row.Cells["FIO"].Value.ToString();
                    td[3, r] = row.Cells["Attestat"].Value.ToString();
                    td[4, r] = row.Cells["Spec"].Value.ToString();
                    td[5, r] = row.Cells["Konkurs"].Value.ToString();
                    td[6, r] = row.Cells["Pasport"].Value.ToString();
                }
            }
            catch (Exception ex)
            {
                WinFormsServ.Error("Ошибка при выводе в Word протокола о допуске: ", ex);
            }
        }
Example #26
0
        public IHttpActionResult GetWordDocHtml(string filename)
        {
            Configs config = new Configs();

            filename = filename.Replace("'", "");
            bool toBeReviewed = false;

            if (filename != "Home")
            {
                string containingDirectory = filename.Split('\\')[1];
                toBeReviewed = containingDirectory == config.ReviewFolder;
            }


            string  root             = config.BlogRoot + "\\";
            string  filenameLocation = root + filename + ".docx";
            WordDoc WordDoc          = new WordDoc(DocX.Load(filenameLocation), filename, toBeReviewed);

            return(Ok(WordDoc.htmlString));
        }
Example #27
0
        /// <summary>
        /// 添加一个新表 参考
        /// </summary>
        public Table AddTable(int rows, int columns)
        {
            object oMissing = System.Reflection.Missing.Value;

            Microsoft.Office.Interop.Word.Application WordApp;
            Microsoft.Office.Interop.Word.Document    WordDoc;
            WordApp         = new Microsoft.Office.Interop.Word.ApplicationClass();
            WordApp.Visible = true;
            WordDoc         = WordApp.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);
            object start = 0;
            object end   = 0;

            Microsoft.Office.Interop.Word.Range tableLocation = WordDoc.Range(ref start, ref end);
            Table newTable = WordDoc.Tables.Add(tableLocation, rows, columns, ref oMissing, ref oMissing);//3行4列的表

            //设置表的格式
            newTable.Borders.Enable           = 1;                            //允许有边框,默认没有边框(为0时报错,1为实线边框,2、3为虚线边框,以后的数字没试过)
            newTable.Borders.OutsideLineWidth = WdLineWidth.wdLineWidth050pt; //边框宽度
            newTable.AllowPageBreaks          = false;
            return(newTable);
        }
Example #28
0
        private void button1_Click(object sender, EventArgs e)
        {
            Word.Document WordDoc;
            var           WordApp = new Word.Application();

            WordApp.Visible = true;
            WordDoc         = WordApp.Documents.Add(Type.Missing, false, Word.WdNewDocumentType.wdNewBlankDocument, true);
            Word.Range wordrange = WordDoc.Range(0, 0);
            Word.Table wordtable = WordDoc.Tables.Add(wordrange, 8, 2, Word.WdDefaultTableBehavior.wdWord9TableBehavior, Word.WdAutoFitBehavior.wdAutoFitWindow);

            Word.Range wordcellrange = WordDoc.Tables[1].Cell(1, 1).Range;
            wordcellrange.Text = "ФИО пациента:";
            wordcellrange      = wordtable.Cell(2, 1).Range;
            wordcellrange.Text = "Дата приема:";
            wordcellrange      = wordtable.Cell(3, 1).Range;
            wordcellrange.Text = "Диагноз:";
            wordcellrange      = wordtable.Cell(4, 1).Range;
            wordcellrange.Text = "Препарат:";
            wordcellrange      = wordtable.Cell(5, 1).Range;
            wordcellrange.Text = "Дополнительно:";
            wordcellrange      = wordtable.Cell(6, 1).Range;
            wordcellrange.Text = "Стоимость услуги:";
            wordcellrange      = wordtable.Cell(7, 1).Range;
            wordcellrange.Text = "Подпись врача:";
            wordcellrange      = wordtable.Cell(8, 1).Range;
            wordcellrange.Text = "Подпись пациента:";

            wordcellrange      = wordtable.Cell(1, 2).Range;
            wordcellrange.Text = dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
            wordcellrange      = wordtable.Cell(2, 2).Range;
            wordcellrange.Text = dataGridView1.SelectedRows[0].Cells[2].Value.ToString();
            wordcellrange      = wordtable.Cell(3, 2).Range;
            wordcellrange.Text = dataGridView1.SelectedRows[0].Cells[4].Value.ToString();
            wordcellrange      = wordtable.Cell(4, 2).Range;
            wordcellrange.Text = dataGridView1.SelectedRows[0].Cells[5].Value.ToString();
            wordcellrange      = wordtable.Cell(5, 2).Range;
            wordcellrange.Text = dataGridView1.SelectedRows[0].Cells[6].Value.ToString();
            wordcellrange      = wordtable.Cell(6, 2).Range;
            wordcellrange.Text = dataGridView1.SelectedRows[0].Cells[8].Value.ToString() + " ₽";
        }
        public TestReport(string workOrderNumber, string testCondition, string partNumber, string dateCode, string testPerformedOn)
        {
            WorkOrderNumber  = workOrderNumber;
            TestCondition    = testCondition;
            TestConditionAbr = testCondition == "As Received" ? "AR" : "TS";
            PartNumber       = partNumber;
            DateCode         = dateCode;
            TestPerformedOn  = testPerformedOn;

            try
            {
                WordApp = new Word.Application();
                //WordApp.Visible = true;
                //var test = Word.Documents
                WordDoc = WordApp.Documents.Open(@"test_report_location\report_template.docx", true, true);
                WordDoc.Activate();
                // make a copy of the report template before entering in any data to use in case number of data rows exceeds limit for one page
                WordApp.ActiveDocument.Bookmarks[@"\Page"].Range.Copy();
                // create correct page break type to add when needed
                //object breakType = Word.WdBreakType.wdPageBreak;
            }
            catch (Exception err)
            {
                sw = new StreamWriter(ErrorLogFilePath, true);
                sw.WriteLine($"{DateTime.Now.ToShortTimeString()}\nReport constructor -- {err.Source}; {err.TargetSite}\n{err.Message}\n");
                sw.Close();

                if (WordDoc != null)
                {
                    WordDoc.Close(Word.WdSaveOptions.wdDoNotSaveChanges, Word.WdOriginalFormat.wdOriginalDocumentFormat, false);
                }
                if (WordApp != null)
                {
                    WordApp.Quit();
                }
                throw;
            }
        }
Example #30
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="intQCInfo_ID">质检编号</param>
        public void AddPrintDemoMethod()
        {
            #region 判断是否安装Word
            if (IsInstallWord() == false)
            {
                MessageBox.Show("请先安装Microsoft Office办公软件");
                return;
            }
            #endregion

            //#region 复制模版
            string file = Common.PrintDemoTitleRoute;//模板路径
            if (!Common.rbool)
            {
                file = Common.PrintDemoTitleRouteTemporary;
            }


            //string newWordFile = CopyWord(file);

            //#endregion

            #region 加载模版
            object oMissing = System.Reflection.Missing.Value;
            Microsoft.Office.Interop.Word.ApplicationClass WordApp;
            Microsoft.Office.Interop.Word.Document         WordDoc;
            WordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
            object fileName = file;
            WordDoc = WordApp.Documents.Open(ref fileName, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
            #endregion

            FindReplace(WordDoc, "[QCInfo_ID]", Common.intQCInfo_ID.ToString(), 0);
            List <string> sqlString = new List <string>();
            sqlString = GetTableSQL(WordDoc);          //获取表格数据的SQL语句


            #region 填充数据

            #region 标题
            if (Common.rboolBT)
            {
                FindReplace(WordDoc, "[标题]", Common.PrintDemoTitle, 0);            //查找指定字段并进行替换操作
            }
            else
            {
                FindReplace(WordDoc, "[标题]", Common.AbnormalPrintDemoTitle, 0);            //查找指定字段并进行替换操作
            }
            #endregion
            string strsql = "";
            #region 非表格字段的数据替换
            if (sqlString.Count >= 1 && WordDoc.Content.Tables.Count >= 1)
            {
                List <string> otherFields = new List <string>();
                otherFields = GetOtherFields(WordDoc);
                strsql      = sqlString[0];//.ElementAt(0);
                if (!string.IsNullOrEmpty(strsql))
                {
                    //strsql = String.Format("select * from View_QCInfo_InTerface where QCInfo_ID={0}", Common.intQCInfo_ID);
                    DataSet dsView_QCInfo_InTerface = LinQBaseDao.Query(strsql);
                    if (dsView_QCInfo_InTerface != null && dsView_QCInfo_InTerface.Tables[0].Rows.Count > 0)
                    {
                        for (int inti = 0; inti < dsView_QCInfo_InTerface.Tables[0].Rows.Count; inti++)
                        {
                            for (int i = 0; i < otherFields.Count; i++)
                            {
                                string oldtext = otherFields.ElementAt(i);
                                string txt     = otherFields.ElementAt(i);
                                if (dsView_QCInfo_InTerface.Tables[0].Rows[inti][txt] != null)
                                {
                                    string newtext = dsView_QCInfo_InTerface.Tables[0].Rows[inti][txt].ToString();
                                    if (newtext.Length < 12)
                                    {
                                        newtext = ISNullMethod(newtext, 12, 0);
                                    }
                                    if (IsDateTime(newtext))
                                    {
                                        newtext = newtext.Substring(0, 10);
                                    }
                                    FindReplace(WordDoc, "[" + oldtext + "]", newtext, 0);            //查找指定字段并进行替换操作
                                }
                            }
                        }
                    }
                    if (strsql != "")
                    {
                        FindReplace(WordDoc, "{" + strsql + "}", "", 0);
                    }
                }
            }

            #endregion

            DataSet ds  = new DataSet();
            DataSet ds1 = new DataSet();
            #region 拆包前水份
            if (sqlString.Count >= 2 && WordDoc.Content.Tables.Count >= 2)
            {
                int intTablesIndex = 2;
                strsql = sqlString[1];//.ElementAt(1);
                if (!string.IsNullOrEmpty(strsql))
                {
                    ds = LinQBaseDao.Query(strsql);
                    if (ds != null && ds.Tables[0].Rows.Count > 0)
                    {
                        int RowNum    = ds.Tables[0].Rows.Count;
                        int ColumnNum = WordDoc.Content.Tables[intTablesIndex].Columns.Count;

                        //读模板
                        int r = 0;     //从第几行计算BlockColumn和IDColumn;
                        for (int i = 1; i <= WordDoc.Content.Tables[intTablesIndex].Rows.Count; i++)
                        {
                            for (int j = 1; j <= WordDoc.Content.Tables[intTablesIndex].Rows[i].Cells.Count; j++)
                            {
                                if (WordDoc.Content.Tables[intTablesIndex].Cell(i, j).Range.Text.Substring(0, WordDoc.Content.Tables[intTablesIndex].Cell(i, j).Range.Text.Length - 2) == "")
                                {
                                    r = i;
                                    break;
                                }
                            }
                            if (r != 0)
                            {
                                break;
                            }
                        }

                        int IDColumn = 0, BlockColumn = 0; //一行可以显示BlockColumn个数据
                        for (int i = 1; i <= WordDoc.Content.Tables[intTablesIndex].Columns.Count; i++)
                        {
                            if (WordDoc.Content.Tables[intTablesIndex].Cell(r, i).Range.Text.Substring(0, WordDoc.Content.Tables[intTablesIndex].Cell(r, i).Range.Text.Length - 2) != "")
                            {
                                IDColumn++;
                            }
                            else
                            {
                                BlockColumn++;
                            }
                        }

                        if (RowNum % BlockColumn != 0)
                        {
                            RowNum = RowNum / BlockColumn + 1;
                        }
                        else
                        {
                            RowNum = RowNum / BlockColumn;
                        }


                        for (int k = WordDoc.Content.Tables[intTablesIndex].Rows.Count + 1; k <= RowNum; k++)        //添加RowNum-1行
                        {
                            WordDoc.Content.Tables[intTablesIndex].Rows.Add(ref oMissing);
                            for (int c = 1; c <= WordDoc.Content.Tables[intTablesIndex].Columns.Count; c++)                                                                                              //初始化新添加行
                            {
                                string str = WordDoc.Content.Tables[intTablesIndex].Cell(k - 1, c).Range.Text.Substring(0, WordDoc.Content.Tables[intTablesIndex].Cell(k - 1, c).Range.Text.Length - 2); //获取表格原来的值
                                if (str == "")
                                {
                                    WordDoc.Content.Tables[intTablesIndex].Cell(k, c).Range.Text = str;
                                }
                                else
                                {
                                    int x = Convert.ToInt32(str);
                                    int y = Convert.ToInt32(IDColumn);
                                    WordDoc.Content.Tables[intTablesIndex].Cell(k, c).Range.Text = Convert.ToString(x + y);
                                }
                            }
                        }


                        /*往表里添加数据*/
                        int pRow = 1, qColumn = 1;
                        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                        {
                            int    find = 1; //1表示没有找到填充格
                            string str  = WordDoc.Content.Tables[intTablesIndex].Cell(pRow, qColumn).Range.Text.Substring(0, WordDoc.Content.Tables[intTablesIndex].Cell(pRow, qColumn).Range.Text.Length - 2);
                            while (find == 1)
                            {
                                while (str == "")
                                {
                                    WordDoc.Content.Tables[intTablesIndex].Cell(pRow, qColumn).Range.Text = ds.Tables[0].Rows[i][0].ToString();
                                    find = 0;
                                    break;
                                }
                                qColumn++;
                                if (qColumn % WordDoc.Content.Tables[intTablesIndex].Columns.Count == 1)
                                {
                                    pRow++;
                                    qColumn = 1;
                                }
                                str = WordDoc.Content.Tables[intTablesIndex].Cell(pRow, qColumn).Range.Text.Substring(0, WordDoc.Content.Tables[intTablesIndex].Cell(pRow, qColumn).Range.Text.Length - 2);
                            }
                        }
                    }
                    if (strsql != "")
                    {
                        FindReplace(WordDoc, "{" + strsql + "}", "", 0);
                    }
                }
            }
            #endregion

            #region 拆包后水份和废纸包重量
            if (sqlString.Count >= 4 && WordDoc.Content.Tables.Count >= 3)
            {
                #region 拆包后水分模板

                int RowNum2 = 0;//行数
                // int ColumnNum2 = WordDoc.Content.Tables[3].Columns.Count;
                //读模板
                int r2 = 0;     //从第几行计算BlockColumn和IDColumn;
                for (int i = 1; i <= WordDoc.Content.Tables[3].Rows.Count; i++)
                {
                    for (int j = 1; j <= WordDoc.Content.Tables[3].Rows[i].Cells.Count; j++)
                    {
                        if (WordDoc.Content.Tables[3].Cell(i, j).Range.Text.Substring(0, WordDoc.Content.Tables[3].Cell(i, j).Range.Text.Length - 2) == "")
                        {
                            r2 = i;
                            break;
                        }
                    }
                    if (r2 != 0)
                    {
                        break;
                    }
                }
                int IDColumn2 = 1, BlockColumn2 = 1; //一行可以显示BlockColumn2个数据
                for (int i = 1; i <= WordDoc.Content.Tables[3].Columns.Count; i++)
                {
                    if (WordDoc.Content.Tables[3].Cell(r2, i).Range.Text.Substring(0, WordDoc.Content.Tables[3].Cell(r2, i).Range.Text.Length - 2) != "")
                    {
                        IDColumn2++;
                    }
                    else
                    {
                        BlockColumn2++;
                    }
                }
                #endregion
                #region 拆包后水份水分不为空
                //*************根据拆包后水份显示行数*******************************************************
                strsql = sqlString[3];//.ElementAt(2);
                if (!string.IsNullOrEmpty(strsql))
                {
                    ds = new DataSet();
                    ds = LinQBaseDao.Query(strsql);
                    if (ds != null && ds.Tables[0].Rows.Count > 0)
                    {
                        RowNum2 = ds.Tables[0].Rows.Count;
                        if (RowNum2 % BlockColumn2 != 0)
                        {
                            RowNum2 = RowNum2 / BlockColumn2 + 1 + 1;   //因为第一行不显示数据,所以要多加一行
                        }
                        else
                        {
                            RowNum2 = RowNum2 / BlockColumn2 + 1;
                        }
                    }
                    if (strsql != "")
                    {
                        FindReplace(WordDoc, "{" + strsql + "}", "", 0);
                    }
                }
                //*************根据废纸包数显示行数*******************************************************
                string strsql1 = sqlString[2];//ElementAt(1);
                if (!string.IsNullOrEmpty(strsql1))
                {
                    ds1 = LinQBaseDao.Query(strsql1);
                    int intcount = ds1.Tables[0].Rows.Count;
                    if (RowNum2 > 0)                           //拆包后水份有数据
                    {
                        if (ds1 != null && intcount > RowNum2) //废纸包有数据
                        {
                            RowNum2 = ds1.Tables[0].Rows.Count;
                        }
                    }
                    else//拆包后水份无数据
                    {
                        if (ds1 != null && intcount > RowNum2)//废纸包有数据
                        {
                            RowNum2 = ds1.Tables[0].Rows.Count;
                            if (RowNum2 % BlockColumn2 != 0)
                            {
                                RowNum2 = RowNum2 / BlockColumn2 + 1 + 1;   //因为第一行不显示数据,所以要多加一行
                            }
                            else
                            {
                                RowNum2 = RowNum2 / BlockColumn2 + 1;
                            }
                        }
                    }
                    FindReplace(WordDoc, "{" + strsql1 + "}", "", 0);
                }
                //****************新添加拆包后水份和废纸包重量行数************************************************
                for (int k = WordDoc.Content.Tables[3].Rows.Count + 1; k <= RowNum2; k++)        //添加RowNum2-1行
                {
                    WordDoc.Content.Tables[3].Rows.Add(ref oMissing);
                    for (int c = 1; c <= WordDoc.Content.Tables[3].Columns.Count; c++)                                                                                 //初始化新添加行
                    {
                        string str = WordDoc.Content.Tables[3].Cell(k - 1, c).Range.Text.Substring(0, WordDoc.Content.Tables[3].Cell(k - 1, c).Range.Text.Length - 2); //获取表格原来的值
                        if (str == "")
                        {
                            WordDoc.Content.Tables[3].Cell(k, c).Range.Text = str;
                        }
                        else
                        {
                            if (c == 2)
                            {
                                WordDoc.Content.Tables[3].Cell(k, c).Range.Text = str;
                            }
                            else if (c == 1)
                            {
                                WordDoc.Content.Tables[3].Cell(k, c).Range.Text = GetChineseNum(str);
                            }
                            else
                            {
                                int x = Convert.ToInt32(str);
                                int y = Convert.ToInt32(BlockColumn2);
                                WordDoc.Content.Tables[3].Cell(k, c).Range.Text = Convert.ToString(x + y);
                            }
                        }
                    }
                }


                /***********************往表里添加数据*******************************/
                int pRow2 = 2, qColumn2 = 1;
                int intindex = 0;
                int ids      = 0; //水分值的下标
                int ids2     = 0; //废纸包值的下标
                if (ds.Tables[0].Rows.Count > 0 || ds1.Tables[0].Rows.Count > 0)
                {
                    while (pRow2 <= WordDoc.Content.Tables[3].Rows.Count)//如果当前行pRow2小于表格的总行数
                    {
                        string str = WordDoc.Content.Tables[3].Cell(pRow2, qColumn2).Range.Text.Substring(0, WordDoc.Content.Tables[3].Cell(pRow2, qColumn2).Range.Text.Length - 2);

                        if (str == "")//如果为空单元格填写水分值
                        {
                            if (ids < ds.Tables[0].Rows.Count)
                            {
                                if (ds.Tables[0].Rows[ids][0] != null)
                                {
                                    WordDoc.Content.Tables[3].Cell(pRow2, qColumn2).Range.Text = ds.Tables[0].Rows[ids][0].ToString();
                                    ids++;
                                }
                            }
                        }
                        else
                        {                                                             //如果不为空单元格填写废纸包重量
                            if (ids2 < ds1.Tables[0].Rows.Count && str.Contains("扎")) //如果当前行数小于废纸包行数,单元格中包含“扎”字
                            {
                                if (ds1.Tables[0].Rows[ids2][0] != null)
                                {
                                    // intindex++;
                                    string strbox = "第" + ds1.Tables[0].Rows[ids2]["QCRecord_DRAW"].ToString() + "扎," + ds1.Tables[0].Rows[ids2]["QCRecord_RESULT"].ToString() + "KG".Trim();
                                    WordDoc.Content.Tables[3].Cell(pRow2, qColumn2).Range.Text = strbox;
                                    ids2++;
                                }
                            }
                        }

                        qColumn2++;
                        if (qColumn2 % WordDoc.Content.Tables[3].Columns.Count == 1)
                        {
                            pRow2++;
                            qColumn2 = 1;
                        }
                    }
                }
                #endregion
            }
            #endregion

            #region  测

            //strsql = sqlString.ElementAt(3);
            //ds = new DataSet();
            //ds = LinQBaseDao.Query(strsql);
            //if (ds != null && ds.Tables[0].Rows.Count > 0)
            //{

            //    int RowNum = ds.Tables[0].Rows.Count;
            //    int ColumnNum = WordDoc.Content.Tables[6].Columns.Count;

            //    //读模板
            //    int r = 0;         //从第几行计算BlockColumn和IDColumn;
            //    for (int i = 1; i <= WordDoc.Content.Tables[6].Rows.Count; i++)
            //    {

            //        for (int j = 1; j <= WordDoc.Content.Tables[6].Rows[i].Cells.Count; j++)
            //        {

            //            if (WordDoc.Content.Tables[6].Cell(i, j).Range.Text.Substring(0, WordDoc.Content.Tables[6].Cell(i, j).Range.Text.Length - 2) == "")
            //            {
            //                r = i;
            //                break;
            //            }
            //        }
            //        if (r != 0)
            //            break;
            //    }

            //    int IDColumn = 0, BlockColumn = 0;   //一行可以显示BlockColumn个数据
            //    for (int i = 1; i <= WordDoc.Content.Tables[6].Columns.Count; i++)
            //    {
            //        if (WordDoc.Content.Tables[6].Cell(r, i).Range.Text.Substring(0, WordDoc.Content.Tables[6].Cell(r, i).Range.Text.Length - 2) != "")
            //            IDColumn++;
            //        else
            //            BlockColumn++;
            //    }

            //    if (RowNum % BlockColumn != 0)
            //    {
            //        RowNum = RowNum / BlockColumn + 1;
            //    }
            //    else
            //    {
            //        RowNum = RowNum / BlockColumn;
            //    }

            //    for (int k = WordDoc.Content.Tables[6].Rows.Count + 1; k <= RowNum; k++)            //添加RowNum-1行
            //    {
            //        WordDoc.Content.Tables[6].Rows.Add(ref oMissing);
            //        for (int c = 1; c <= WordDoc.Content.Tables[6].Columns.Count; c++)            //初始化新添加行
            //        {
            //            string str = WordDoc.Content.Tables[6].Cell(k - 1, c).Range.Text.Substring(0, WordDoc.Content.Tables[6].Cell(k - 1, c).Range.Text.Length - 2);      //获取表格原来的值
            //            if (str == "")
            //            {
            //                WordDoc.Content.Tables[6].Cell(k, c).Range.Text = str;
            //            }
            //            else
            //            {
            //                int x = Convert.ToInt32(str);
            //                int y = Convert.ToInt32(IDColumn);
            //                WordDoc.Content.Tables[6].Cell(k, c).Range.Text = Convert.ToString(x + y);
            //            }
            //        }

            //    }

            //}
            //if (strsql != "")
            //{
            //    FindReplace(WordDoc, "{" + strsql + "}", "", 0);

            //}
            #endregion
            #endregion

            #region 打印预览
            WordApp.Visible = true;
            WordDoc.PrintPreview();//打印预览
            WordDoc.ReadingLayoutSizeX = 1024;
            WordDoc.ReadingLayoutSizeY = 756;
            #endregion


            #region 打印设置
            ////打印设置
            //try
            //{
            //    int dialogResult = WordApp.Dialogs[Microsoft.Office.Interop.Word.WdWordDialog.wdDialogFilePrint].Show(ref oMissing);
            //    if (dialogResult == 1)
            //    {
            //        //打印
            //        WordDoc.PrintOut(ref oMissing, ref oMissing, ref oMissing, ref oMissing,
            //              ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
            //              ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
            //              ref oMissing, ref oMissing, ref oMissing, ref oMissing);

            //    }
            //    while (WordApp.BackgroundPrintingStatus > 0)
            //    {
            //        System.Threading.Thread.Sleep(250);
            //    }
            //}
            //catch (Exception ex)
            //{

            //    //Common.WriteTextLog("打印 GetPrint()" + ex.Message.ToString());
            //}
            //finally
            //{
            //    //消除Word 进程
            //    object SaveChanges = Microsoft.Office.Interop.Word.WdSaveOptions.wdDoNotSaveChanges;

            //    WordDoc.Close(ref SaveChanges, ref oMissing, ref oMissing);
            //    if (WordApp != null)
            //        System.Runtime.InteropServices.Marshal.ReleaseComObject(WordDoc);
            //    WordDoc = null;


            //    WordApp.Quit(ref SaveChanges, ref oMissing, ref oMissing);
            //    GC.Collect();

            //}

            //object format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatRTF;
            //object Target = System.Windows.Forms.Application.StartupPath + "//temp.rtf";
            //// 转换格式
            //oDoc.SaveAs(ref Target, ref format,
            //           ref oMissing, ref oMissing, ref oMissing,
            //           ref oMissing, ref oMissing, ref oMissing,
            //           ref oMissing, ref oMissing, ref oMissing,
            //           ref oMissing, ref oMissing, ref oMissing,
            //           ref oMissing, ref oMissing);
            #endregion

            //    OnClose(WordApp);
            //    MessageBox.Show("报表已生成!");

            //}
            //else
            //{
            //    return;
            //}
        }