Exemple #1
0
        public static void asociadosCategoria(DataGridView grd, string periodoRep, string usuarioCreador, double total, string opcion, string idR, string nombreR, string categoriaR)
        {
            crearCarpeta();

            object oEndOfDoc = "\\endofdoc";
            object oTemplate = Application.StartupPath + @"\tacticos\asociados.dotx";
            object ObjMiss   = System.Reflection.Missing.Value;

            Word.Application oWord = new Word.Application();
            Word.Document    oDoc  = oWord.Documents.Add(ref oTemplate, ref ObjMiss, ref ObjMiss, ref ObjMiss);

            // Periodo de resultados
            object periodo = "periodo";

            Word.Range periodoDoc = oDoc.Bookmarks.get_Item(ref periodo).Range;
            periodoDoc.Text = periodoRep;
            object rango1 = periodoDoc;

            oDoc.Bookmarks.Add("periodo", ref rango1);

            // Nombre de usuario que crea al reporte
            object usuario = "usuario";

            Word.Range usuarioDoc = oDoc.Bookmarks.get_Item(ref usuario).Range;
            usuarioDoc.Text = usuarioCreador;
            object rango2 = usuarioDoc;

            oDoc.Bookmarks.Add("usuario", ref rango2);

            // Parametros
            object id = "id";

            Word.Range idDoc = oDoc.Bookmarks.get_Item(ref id).Range;
            idDoc.Text = idR;
            object rango3 = idDoc;

            oDoc.Bookmarks.Add("id", ref rango3);

            object nombre = "nombre";

            Word.Range nombreDoc = oDoc.Bookmarks.get_Item(ref nombre).Range;
            nombreDoc.Text = nombreR;
            object rango4 = nombreDoc;

            oDoc.Bookmarks.Add("nombre", ref rango4);

            object categoria = "categoria";

            Word.Range categoriaDoc = oDoc.Bookmarks.get_Item(ref categoria).Range;
            categoriaDoc.Text = categoriaR;
            object rango5 = categoriaDoc;

            oDoc.Bookmarks.Add("categoria", ref rango5);

            //Insertar una tabla de n x m , llenarla con datagrid y estilizar la primera línea
            //en negritas y cursivas.
            Word.Table oTable;
            Word.Range wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
            oTable = oDoc.Tables.Add(wrdRng, grd.RowCount, grd.ColumnCount, ref ObjMiss, ref ObjMiss);
            oTable.Range.ParagraphFormat.SpaceAfter = 6;

            oTable.Rows[1].Range.Font.Bold   = 1;
            oTable.Rows[1].Range.Font.Italic = 1;
            oTable.Borders.Enable            = 1;
            int iCol = 0;

            foreach (DataGridViewColumn column in grd.Columns)
            {
                if (column.Visible)
                {
                    oTable.Cell(1, ++iCol).Range.Text = column.HeaderText;
                }
            }
            for (int i = 0; i < grd.Rows.Count - 1; i++)
            {
                for (int j = 0; j < grd.Columns.Count; j++)
                {
                    oTable.Cell(i + 2, j + 1).Range.Text = grd.Rows[i].Cells[j].Value.ToString();
                }
            }

            //Agregar total después de la tabla
            Word.Paragraph oPara1;
            object         oRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;

            oPara1 = oDoc.Content.Paragraphs.Add(ref oRng);
            oPara1.Range.InsertParagraphBefore();
            oPara1.Range.Text         = "Total: $" + total;
            oPara1.Range.Font.Bold    = 1;
            oPara1.Format.SpaceBefore = 24;
            oPara1.Range.InsertParagraphAfter();

            switch (opcion)
            {
            case "word":
                oDoc.SaveAs2(@path + "Asociados por categoría " + @fecha, Word.WdSaveFormat.wdFormatDocumentDefault);
                break;

            case "pdf":
                oDoc.SaveAs2(@path + "Asociados por categoría " + @fecha, Word.WdSaveFormat.wdFormatPDF);
                Process.Start(@path + "\\Asociados por categoría " + @fecha + ".pdf");
                break;

            case "print":
                oDoc.PrintOut(ref ObjMiss, ref ObjMiss, ref ObjMiss, ref ObjMiss);
                break;
            }

            oDoc.Close(Word.WdSaveOptions.wdDoNotSaveChanges);
        }
Exemple #2
0
        private void Print_Jornal()
        {
            // Инициализация Word
            this.Cursor = Cursors.WaitCursor;
            Word.Application o_Word      = new Word.Application();
            Word.Document    o_Doc       = new Word.Document();
            string           d_PrintName = o_Word.ActivePrinter;
            string           n_PrintName = comboBox1.SelectedItem.ToString();

            if (chkVisible.Checked)
            {
                o_Word.Visible = false;
            }
            else
            {
                o_Word.Visible = true;
            }
            string path_toFile = txtJornal.Text + "\\" + comboBox2.SelectedItem.ToString();
            string dt_pick     = dTPicker.Value.ToString("dd MMMM yyyy г.");

            object fileNameJorn          = path_toFile;
            Object confirmConversions    = Type.Missing;
            Object readOnly              = Type.Missing;
            Object addToRecentFiles      = Type.Missing;
            Object passwordDocument      = Type.Missing;
            Object passwordTemplate      = Type.Missing;
            Object revert                = Type.Missing;
            Object writePasswordDocument = Type.Missing;
            Object writePasswordTemplate = Type.Missing;
            Object format                = Type.Missing;
            Object encoding              = Microsoft.Office.Core.MsoEncoding.msoEncodingOEMCyrillicII;
            Object visible               = Type.Missing;
            Object openConflictDocument  = Type.Missing;
            Object openAndRepair         = Type.Missing;
            Object documentDirection     = Type.Missing;
            Object noEncodingDialog      = Type.Missing;

            o_Word.Documents.Open(ref fileNameJorn,
                                  ref confirmConversions,
                                  ref readOnly,
                                  ref addToRecentFiles,
                                  ref passwordDocument,
                                  ref passwordTemplate,
                                  ref revert,
                                  ref writePasswordDocument,
                                  ref writePasswordTemplate,
                                  ref format,
                                  ref encoding,
                                  ref visible,
                                  ref openConflictDocument,
                                  ref openAndRepair,
                                  ref documentDirection,
                                  ref noEncodingDialog);
            o_Doc = o_Word.Documents.Application.ActiveDocument;

            Word.Selection o_Sel = o_Word.Selection;

            o_Sel.HomeKey(Unit: Word.WdUnits.wdStory, Extend: Word.WdMovementType.wdMove);
            o_Sel.EndKey(Unit: Word.WdUnits.wdLine, Extend: Type.Missing);
            o_Sel.TypeText(" " + dt_pick);

            o_Word.ActivePrinter = n_PrintName;
            Object background           = Type.Missing;
            Object append               = Type.Missing;
            Object range                = Type.Missing;
            Object outputFileName       = Type.Missing;
            Object from                 = Type.Missing;
            Object to                   = Type.Missing;
            Object item                 = Type.Missing;
            Object copies               = Type.Missing;
            Object pages                = Type.Missing;
            Object pageType             = Type.Missing;
            Object printToFile          = Type.Missing;
            Object collate              = Type.Missing;
            Object fileName             = Type.Missing;
            Object activePrinterMacGX   = Type.Missing;
            Object manualDuplexPrint    = Type.Missing;
            Object printZoomColumn      = Type.Missing;
            Object printZoomRow         = Type.Missing;
            Object printZoomPaperWidth  = Type.Missing;
            Object printZoomPaperHeight = Type.Missing;

            o_Doc.PrintOut(ref background, ref append,
                           ref range, ref outputFileName, ref from, ref to,
                           ref item, ref copies, ref pages, ref pageType,
                           ref printToFile, ref collate, ref activePrinterMacGX,
                           ref manualDuplexPrint, ref printZoomColumn, ref printZoomRow,
                           ref printZoomPaperWidth, ref printZoomPaperHeight);

            o_Word.ActivePrinter = d_PrintName;

            Thread.Sleep(2000);

            Object saveChanges    = Word.WdSaveOptions.wdDoNotSaveChanges;
            Object originalFormat = Type.Missing;
            Object routeDocument  = Type.Missing;

            ((Word._Application)o_Word).Quit(ref saveChanges,
                                             ref originalFormat, ref routeDocument);
            o_Word = null;

            this.Cursor = Cursors.Default;
            tSSlb.Text  = "Файл " + comboBox2.SelectedItem.ToString() + " отправлен на " + n_PrintName;
        }
Exemple #3
0
        public static void proyeccion(DataGridView grd, string periodoRep, string usuarioCreador, string opcion, string creditoR, string asociadoR,
                                      string idasociadoR, double moraR, double cuotapropuestaR, double plazopropuestoR, double cuotaactualR, double restanteactualR)
        {
            crearCarpeta();

            object oEndOfDoc = "\\endofdoc";
            object oTemplate = Application.StartupPath + @"\tacticos\proyeccion.dotx";
            object ObjMiss   = System.Reflection.Missing.Value;

            Word.Application oWord = new Word.Application();
            Word.Document    oDoc  = oWord.Documents.Add(ref oTemplate, ref ObjMiss, ref ObjMiss, ref ObjMiss);

            // Periodo de resultados
            object periodo = "periodo";

            Word.Range periodoDoc = oDoc.Bookmarks.get_Item(ref periodo).Range;
            periodoDoc.Text = periodoRep;
            object rango1 = periodoDoc;

            oDoc.Bookmarks.Add("periodo", ref rango1);

            // Nombre de usuario que crea al reporte
            object usuario = "usuario";

            Word.Range usuarioDoc = oDoc.Bookmarks.get_Item(ref usuario).Range;
            usuarioDoc.Text = usuarioCreador;
            object rango2 = usuarioDoc;

            oDoc.Bookmarks.Add("usuario", ref rango2);

            // Parametros
            object credito = "credito";

            Word.Range creditoDoc = oDoc.Bookmarks.get_Item(ref credito).Range;
            creditoDoc.Text = creditoR;
            object rango3 = creditoDoc;

            oDoc.Bookmarks.Add("credito", ref rango3);

            object asociado = "asociado";

            Word.Range asociadoDoc = oDoc.Bookmarks.get_Item(ref asociado).Range;
            asociadoDoc.Text = asociadoR;
            object rango4 = asociadoDoc;

            oDoc.Bookmarks.Add("asociado", ref rango4);

            object idasociado = "idasociado";

            Word.Range idasociadoDoc = oDoc.Bookmarks.get_Item(ref idasociado).Range;
            idasociadoDoc.Text = idasociadoR;
            object rango5 = idasociadoDoc;

            oDoc.Bookmarks.Add("idasociado", ref rango5);

            object mora = "mora";

            Word.Range moraDoc = oDoc.Bookmarks.get_Item(ref mora).Range;
            moraDoc.Text = moraR + "";
            object rango6 = moraDoc;

            oDoc.Bookmarks.Add("mora", ref rango6);

            object cuotapropuesta = "cuotapropuesta";

            Word.Range cuotapropuestaDoc = oDoc.Bookmarks.get_Item(ref cuotapropuesta).Range;
            cuotapropuestaDoc.Text = cuotapropuestaR + "";
            object rango7 = cuotapropuestaDoc;

            oDoc.Bookmarks.Add("cuotapropuesta", ref rango7);

            object plazopropuesto = "plazopropuesto";

            Word.Range plazopropuestoDoc = oDoc.Bookmarks.get_Item(ref plazopropuesto).Range;
            plazopropuestoDoc.Text = plazopropuestoR + "";
            object rango8 = plazopropuestoDoc;

            oDoc.Bookmarks.Add("plazopropuesto", ref rango8);

            object cuotaactual = "cuotaactual";

            Word.Range cuotaactualDoc = oDoc.Bookmarks.get_Item(ref cuotaactual).Range;
            cuotaactualDoc.Text = cuotaactualR + "";
            object rango9 = cuotaactualDoc;

            oDoc.Bookmarks.Add("cuotaactual", ref rango9);

            object restanteactual = "restanteactual";

            Word.Range restanteactualDoc = oDoc.Bookmarks.get_Item(ref restanteactual).Range;
            restanteactualDoc.Text = restanteactualR + "";
            object rango10 = restanteactualDoc;

            oDoc.Bookmarks.Add("restanteactual", ref rango10);

            switch (opcion)
            {
            case "word":
                oDoc.SaveAs2(@path + "Proyección de pagos por cuotas " + @fecha, Word.WdSaveFormat.wdFormatDocumentDefault);
                break;

            case "pdf":
                oDoc.SaveAs2(@path + "Proyección de pagos por cuotas " + @fecha, Word.WdSaveFormat.wdFormatPDF);
                Process.Start(@path + "\\Proyección de pagos por cuotas " + @fecha + ".pdf");
                break;

            case "print":
                oDoc.PrintOut(ref ObjMiss, ref ObjMiss, ref ObjMiss, ref ObjMiss);
                break;
            }

            oDoc.Close(Word.WdSaveOptions.wdDoNotSaveChanges);
        }
Exemple #4
0
        //public static class myPrinters
        //{
        //    [DllImport("winspool.drv", CharSet = CharSet.Auto, SetLastError = true)]
        //    public static extern bool SetDefaultPrinter(string Name);
        //}

        public void Format_otvet()
        {
            // Инициализация Word
            this.Cursor = Cursors.WaitCursor;
            Word.Application o_Word = new Word.Application();
            Word.Document    o_Doc  = new Word.Document();
            //string defaultPrinter;
            //string n_PrintName = comboBox1.SelectedItem.ToString();
            //var printServer = new LocalPrintServer();
            //defaultPrinter = printServer.DefaultPrintQueue.Name;
            //myPrinters.SetDefaultPrinter(n_PrintName);
            string d_PrintName = o_Word.ActivePrinter;
            string n_PrintName = comboBox1.SelectedItem.ToString();

            if (chkVisible.Checked)
            {
                o_Word.Visible = false;
            }
            else
            {
                o_Word.Visible = true;
            }

            //Открытие и редактирование документа
            Object filename              = txtFrom.Text + "\\otvet.txt";
            Object confirmConversions    = Type.Missing;
            Object readOnly              = Type.Missing;
            Object addToRecentFiles      = Type.Missing;
            Object passwordDocument      = Type.Missing;
            Object passwordTemplate      = Type.Missing;
            Object revert                = Type.Missing;
            Object writePasswordDocument = Type.Missing;
            Object writePasswordTemplate = Type.Missing;
            Object format                = Type.Missing;
            Object encoding              = Microsoft.Office.Core.MsoEncoding.msoEncodingOEMCyrillicII;
            Object visible               = Type.Missing;
            Object openConflictDocument  = Type.Missing;
            Object openAndRepair         = Type.Missing;
            Object documentDirection     = Type.Missing;
            Object noEncodingDialog      = Type.Missing;

            if (!System.IO.File.Exists(filename.ToString()))
            {
                o_Word.Visible = true;
                MessageBox.Show("Файл " + filename.ToString() + " не найден.", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            o_Word.Documents.Open(ref filename,
                                  ref confirmConversions,
                                  ref readOnly,
                                  ref addToRecentFiles,
                                  ref passwordDocument,
                                  ref passwordTemplate,
                                  ref revert,
                                  ref writePasswordDocument,
                                  ref writePasswordTemplate,
                                  ref format,
                                  ref encoding,
                                  ref visible,
                                  ref openConflictDocument,
                                  ref openAndRepair,
                                  ref documentDirection,
                                  ref noEncodingDialog);

            //Word.Document Doc = new Word.Document();
            o_Doc = o_Word.Documents.Application.ActiveDocument;
            o_Doc.PageSetup.LeftMargin   = o_Word.CentimetersToPoints(1.27f);
            o_Doc.PageSetup.RightMargin  = o_Word.CentimetersToPoints(1.27f);
            o_Doc.PageSetup.TopMargin    = o_Word.CentimetersToPoints(1.27f);
            o_Doc.PageSetup.BottomMargin = o_Word.CentimetersToPoints(1.27f);
            Word.Find      o_Find = o_Word.Selection.Find;
            Word.Selection o_Sel  = o_Word.Selection;

            o_Find.ClearFormatting();
            o_Find.Replacement.ClearFormatting();
            o_Find.Text = "ФИО: Переходченко М.В.";
            //Object wrap = Type.Missing; ;
            //Object replace = Type.Missing; ;
            o_Find.Execute(FindText: Type.Missing,
                           MatchCase: false,
                           MatchWholeWord: false,
                           MatchWildcards: false,
                           MatchSoundsLike: Type.Missing,
                           MatchAllWordForms: false,
                           Forward: true,
                           Wrap: Type.Missing,
                           Format: false,
                           ReplaceWith: Type.Missing, Replace: Type.Missing);


            o_Sel.EndKey(Unit: Word.WdUnits.wdLine, Extend: Type.Missing);
            o_Sel.HomeKey(Unit: Word.WdUnits.wdStory, Extend: Word.WdMovementType.wdExtend);
            o_Sel.Delete();

            o_Find.ClearFormatting();
            o_Find.Replacement.ClearFormatting();
            o_Find.Text             = "----------------------------------------------------------------------------^p----------------------------------------------------------------------------";
            o_Find.Replacement.Text = "----------------------------------------------------------------------------^m----------------------------------------------------------------------------";
            Object wrap    = Word.WdFindWrap.wdFindContinue;
            Object replace = Word.WdReplace.wdReplaceAll;

            o_Find.Execute(FindText: Type.Missing,
                           MatchCase: false,
                           MatchWholeWord: false,
                           MatchWildcards: false,
                           MatchSoundsLike: Type.Missing,
                           MatchAllWordForms: false,
                           Forward: true,
                           Wrap: wrap,
                           Format: false,
                           ReplaceWith: Type.Missing, Replace: replace);
            o_Find.ClearFormatting();
            o_Find.Replacement.ClearFormatting();
            int PagesCount = o_Word.Documents.Application.ActiveDocument.Content.ComputeStatistics(Word.WdStatistic.wdStatisticPages);

            //Сохранение в формате .doc
            //Object s_fileName = txtFrom.Text + "\\arch\\otvet.doc";
            //Object fileformat = Word.WdSaveFormat.wdFormatDocument;
            //o_Doc.SaveAs(ref s_fileName, ref fileformat);

            o_Word.ActivePrinter = n_PrintName;
            Object background           = Type.Missing;
            Object append               = Type.Missing;
            Object range                = Type.Missing;
            Object outputFileName       = Type.Missing;
            Object from                 = Type.Missing;
            Object to                   = Type.Missing;
            Object item                 = Type.Missing;
            Object copies               = Type.Missing;
            Object pages                = Type.Missing;
            Object pageType             = Type.Missing;
            Object printToFile          = Type.Missing;
            Object collate              = Type.Missing;
            Object fileName             = Type.Missing;
            Object activePrinterMacGX   = Type.Missing;
            Object manualDuplexPrint    = Type.Missing;
            Object printZoomColumn      = Type.Missing;
            Object printZoomRow         = Type.Missing;
            Object printZoomPaperWidth  = Type.Missing;
            Object printZoomPaperHeight = Type.Missing;

            o_Doc.PrintOut(ref background, ref append,
                           ref range, ref outputFileName, ref from, ref to,
                           ref item, ref copies, ref pages, ref pageType,
                           ref printToFile, ref collate, ref activePrinterMacGX,
                           ref manualDuplexPrint, ref printZoomColumn, ref printZoomRow,
                           ref printZoomPaperWidth, ref printZoomPaperHeight);

            Thread.Sleep(6000);

            o_Word.ActivePrinter = d_PrintName;
            Object saveChanges    = Word.WdSaveOptions.wdDoNotSaveChanges;
            Object originalFormat = Type.Missing;
            Object routeDocument  = Type.Missing;

            ((Word._Application)o_Word).Quit(ref saveChanges,
                                             ref originalFormat, ref routeDocument);
            o_Word = null;
            //Process.Start(@"winword.exe", string.Format(@"{0} /mFilePrintDefault /mFileExit /q /n", s_fileName));
            //myPrinters.SetDefaultPrinter(defaultPrinter);
            this.Cursor = Cursors.Default;
            tSSlb.Text  = "Файл " + filename + " отправлен на " + n_PrintName + " Всего страниц: " + PagesCount.ToString();
        }
Exemple #5
0
        private void Format_vipS()
        {
            // Инициализация Word
            this.Cursor = Cursors.WaitCursor;
            Word.Application o_Word      = new Word.Application();
            Word.Document    o_Doc       = new Word.Document();
            string           d_PrintName = o_Word.ActivePrinter;
            string           n_PrintName = comboBox1.SelectedItem.ToString();

            if (chkVisible.Checked)
            {
                o_Word.Visible = false;
            }
            else
            {
                o_Word.Visible = true;
            }
            string[] Filelst = System.IO.Directory.GetFiles(txtFrom.Text, "vp*.txt");

            if (System.IO.File.Exists(Filelst.Length.ToString()))
            {
                o_Word.Visible = true;
                MessageBox.Show("Файл " + Filelst.ToString() + " не найден.", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            //Открытие и редактирование документа
            Object filename              = Filelst[0];
            Object confirmConversions    = Type.Missing;
            Object readOnly              = Type.Missing;
            Object addToRecentFiles      = Type.Missing;
            Object passwordDocument      = Type.Missing;
            Object passwordTemplate      = Type.Missing;
            Object revert                = Type.Missing;
            Object writePasswordDocument = Type.Missing;
            Object writePasswordTemplate = Type.Missing;
            Object format                = Type.Missing;
            Object encoding              = Microsoft.Office.Core.MsoEncoding.msoEncodingOEMCyrillicII;
            Object visible               = Type.Missing;
            Object openConflictDocument  = Type.Missing;
            Object openAndRepair         = Type.Missing;
            Object documentDirection     = Type.Missing;
            Object noEncodingDialog      = Type.Missing;

            o_Word.Documents.Open(ref filename,
                                  ref confirmConversions,
                                  ref readOnly,
                                  ref addToRecentFiles,
                                  ref passwordDocument,
                                  ref passwordTemplate,
                                  ref revert,
                                  ref writePasswordDocument,
                                  ref writePasswordTemplate,
                                  ref format,
                                  ref encoding,
                                  ref visible,
                                  ref openConflictDocument,
                                  ref openAndRepair,
                                  ref documentDirection,
                                  ref noEncodingDialog);

            o_Doc = o_Word.Documents.Application.ActiveDocument;
            o_Doc.PageSetup.PaperSize = Word.WdPaperSize.wdPaperA3;
            //o_Doc.PageSetup.Orientation = Word.WdOrientation.wdOrientLandscape; // Word.WdOrientation.wdOrientPortrait
            //o_Doc.PageSetup.PageWidth = o_Word.CentimetersToPoints(29.7f);
            //o_Doc.PageSetup.PageHeight = o_Word.CentimetersToPoints(42f);

            o_Word.ActivePrinter = n_PrintName;

            Object background           = Type.Missing;
            Object append               = Type.Missing;
            Object range                = Type.Missing;
            Object outputFileName       = Type.Missing;
            Object from                 = Type.Missing;
            Object to                   = Type.Missing;
            Object item                 = Type.Missing;
            Object copies               = Type.Missing;
            Object pages                = Type.Missing;
            Object pageType             = Type.Missing;
            Object printToFile          = Type.Missing;
            Object collate              = Type.Missing;
            Object fileName             = Type.Missing;
            Object activePrinterMacGX   = Type.Missing;
            Object manualDuplexPrint    = Type.Missing;
            Object printZoomColumn      = Type.Missing;
            Object printZoomRow         = Type.Missing;
            Object printZoomPaperWidth  = Type.Missing;
            Object printZoomPaperHeight = Type.Missing;

            o_Doc.PrintOut(ref background, ref append,
                           ref range, ref outputFileName, ref from, ref to,
                           ref item, ref copies, ref pages, ref pageType,
                           ref printToFile, ref collate, ref activePrinterMacGX,
                           ref manualDuplexPrint, ref printZoomColumn, ref printZoomRow,
                           ref printZoomPaperWidth, ref printZoomPaperHeight);

            o_Word.ActivePrinter = d_PrintName;

            Thread.Sleep(2000);

            Object saveChanges    = Word.WdSaveOptions.wdDoNotSaveChanges;
            Object originalFormat = Type.Missing;
            Object routeDocument  = Type.Missing;

            ((Word._Application)o_Word).Quit(ref saveChanges,
                                             ref originalFormat, ref routeDocument);
            o_Word = null;

            this.Cursor = Cursors.Default;
            tSSlb.Text  = "Файл " + filename + " отправлен на " + n_PrintName;
        }
Exemple #6
0
        private void PrintAgenda()
        {
            object nullobject = Type.Missing;
            object missing    = Type.Missing;

            object fileName  = AppDefaultSetting.surat_masuk_disposisi_template_path;
            object TfileName = System.Windows.Forms.Application.StartupPath + @"\agenda_printout_template.docx";

            Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application {
                Visible = true
            };
            if (!System.IO.File.Exists((string)fileName))
            {
                MessageBox.Show(this, "Template tidak ditemukan, mohon periksa kembali atau hubungi administrator.",
                                "Template Tidak Ditemukan", MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1);
                return;
            }

            Microsoft.Office.Interop.Word.Document aDoc = wordApp.Documents.Open(ref fileName, ref missing, ref missing, ref missing, ref missing, ref missing,
                                                                                 ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);

            aDoc.Activate();

            FindAndReplace(wordApp, "[nomor_agenda]", nomor_agenda, false);
            FindAndReplace(wordApp, "[kategori]", dropDownTipe.Text, false);
            FindAndReplace(wordApp, "[tanggal_terima]", string.Format("{0:" + AppDefaultSetting.surat_masuk_date_format + "}", dtTanggalMasuk.Value), false);
            FindAndReplace(wordApp, "[nomor_surat]", txtNomorSurat.Text, false);
            FindAndReplace(wordApp, "[tanggal_surat]", string.Format("{0:" + AppDefaultSetting.surat_masuk_date_format + "}", dtTanggalSurat.Value), false);
            FindAndReplace(wordApp, "[asal_surat]", txtAsalSurat.Text, false);
            FindAndReplace(wordApp, "[perihal]", txtPerihalSurat.Text, false);
            FindAndReplace(wordApp, "[tingkat_keamanan]", dropDownTingkatKeamanan.Text, false);
            FindAndReplace(wordApp, "[ringkasan_isi]", txtRingkasanIsi.Text, false);
            FindAndReplace(wordApp, "[lampiran]", txtLampiran.Text, false);


            FindAndReplace(wordApp, "[tanggal_disposisi]", string.Format("{0:" + AppDefaultSetting.surat_masuk_date_format + "}", dtTanggalDisposisi.Value), false);
            FindAndReplace(wordApp, "[tujuan_disposisi]", txtTujuanDisposisi.Text, false);
            FindAndReplace(wordApp, "[isi_disposisi]", txtIsisDisposisi.Text, false);

            FindAndReplace(wordApp, "[referensi_surat]", txtReferensiSurat.Text, false);
            FindAndReplace(wordApp, "[lokasi_fisik]", ddLokasiFisikSurat.Text, false);
            FindAndReplace(wordApp, "[info_lokasi]", txtKeteranganLokasi.Text, false);
            FindAndReplace(wordApp, "[jenis_pengiriman]", ddJenisPengiriman.Text, false);
            FindAndReplace(wordApp, "[info_pengiriman]", txtInfoPengiriman.Text, false);

            FindAndReplace(wordApp, "[datetime_print]", string.Format("{0:" + AppDefaultSetting.surat_masuk_date_format + "}", DateTime.Now), false);
            FindAndReplace(wordApp, "[user]", T8UserLoginInfo.Username, false);

            for (int i = 0; i < dtKategori.Rows.Count; i++)
            {
                if (dropDownTipe.Text.ToLower() == dtKategori.Rows[i][0].ToString().ToLower())
                {
                    FindAndReplace(wordApp, "[o:" + dtKategori.Rows[i][1].ToString() + "]", "<b>" + dtKategori.Rows[i][1].ToString() + "</b>", false);
                    FindAndReplace(wordApp, "<b>" + dtKategori.Rows[i][1].ToString() + "</b>", dtKategori.Rows[i][1].ToString(), true);
                }
                else
                {
                    FindAndReplace(wordApp, "[o:" + dtKategori.Rows[i][1].ToString() + "]", dtKategori.Rows[i][1].ToString(), false);
                }
            }

            for (int j = 0; j < dtTKKeamanan.Rows.Count; j++)
            {
                if (dropDownTingkatKeamanan.Text.ToLower() == dtTKKeamanan.Rows[j][0].ToString().ToLower())
                {
                    FindAndReplace(wordApp, "[o:" + dtTKKeamanan.Rows[j][1].ToString() + "]", "<b>" + dtTKKeamanan.Rows[j][1].ToString() + "</b>", false);
                    FindAndReplace(wordApp, "<b>" + dtTKKeamanan.Rows[j][1].ToString() + "</b>", dtTKKeamanan.Rows[j][1].ToString(), true);
                }
                else
                {
                    FindAndReplace(wordApp, "[o:" + dtTKKeamanan.Rows[j][1].ToString() + "]", dtTKKeamanan.Rows[j][1].ToString(), false);
                }
            }

            for (int k = 0; k < dtAsalSurat.Rows.Count; k++)
            {
                if (txtAsalSurat.Text.ToLower() == dtAsalSurat.Rows[k][0].ToString().ToLower())
                {
                    FindAndReplace(wordApp, "[o:" + dtAsalSurat.Rows[k][1].ToString() + "]", "<b>" + dtAsalSurat.Rows[k][1].ToString() + "</b>", false);
                    FindAndReplace(wordApp, "<b>" + dtAsalSurat.Rows[k][1].ToString() + "</b>", dtAsalSurat.Rows[k][1].ToString(), true);
                }
                else
                {
                    FindAndReplace(wordApp, "[o:" + dtAsalSurat.Rows[k][1].ToString() + "]", dtAsalSurat.Rows[k][1].ToString(), false);
                }
            }

            for (int l = 0; l < dtPosisiSurat.Rows.Count; l++)
            {
                if (txtTujuanDisposisi.Text.ToLower() == dtPosisiSurat.Rows[l][0].ToString().ToLower())
                {
                    FindAndReplace(wordApp, "[o:" + dtPosisiSurat.Rows[l][1].ToString() + "]", "<b>" + dtPosisiSurat.Rows[l][1].ToString() + "</b>", false);
                    FindAndReplace(wordApp, "<b>" + dtPosisiSurat.Rows[l][1].ToString() + "</b>", dtPosisiSurat.Rows[l][1].ToString(), true);
                }
                else
                {
                    FindAndReplace(wordApp, "[o:" + dtPosisiSurat.Rows[l][1].ToString() + "]", dtPosisiSurat.Rows[l][1].ToString(), false);
                }
            }

            wordApp.ActiveDocument.SaveAs(ref TfileName,
                                          ref nullobject, ref nullobject, ref nullobject, ref nullobject, ref nullobject,
                                          ref nullobject, ref nullobject, ref nullobject, ref nullobject, ref nullobject,
                                          ref nullobject, ref nullobject, ref nullobject, ref nullobject, ref nullobject);

            object copies   = GUI.GeneralSettings.OtomatisCetakAgendaValue.ToString();
            object pages    = "1";
            object range    = Microsoft.Office.Interop.Word.WdPrintOutRange.wdPrintCurrentPage;
            object items    = Microsoft.Office.Interop.Word.WdPrintOutItem.wdPrintDocumentContent;
            object pageType = Microsoft.Office.Interop.Word.WdPrintOutPages.wdPrintAllPages;
            object oTrue    = true;
            object oFalse   = false;

            Microsoft.Office.Interop.Word.Document TaDoc = wordApp.Documents.Open(ref TfileName, ReadOnly: false, Visible: true);

            TaDoc.PrintOut(
                ref oTrue, ref oFalse, ref range, ref nullobject, ref nullobject, ref nullobject,
                ref items, ref copies, ref pages, ref pageType, ref oFalse, ref oTrue,
                ref nullobject, ref oFalse, ref nullobject, ref nullobject, ref nullobject, ref nullobject);

            object doNotSaved = Microsoft.Office.Interop.Word.WdSaveOptions.wdDoNotSaveChanges;

            ((Microsoft.Office.Interop.Word._Application)wordApp).Quit(ref nullobject, ref nullobject, ref nullobject);
        }
Exemple #7
0
        public void Format_vipLS()
        {
            // Инициализация Word
            this.Cursor = Cursors.WaitCursor;
            Word.Application o_Word      = new Word.Application();
            Word.Document    o_Doc       = new Word.Document();
            string           d_PrintName = o_Word.ActivePrinter;
            string           n_PrintName = comboBox1.SelectedItem.ToString();

            if (chkVisible.Checked)
            {
                o_Word.Visible = false;
            }
            else
            {
                o_Word.Visible = true;
            }

            //Открытие и редактирование документа
            Object filename              = txtFrom.Text + "\\vips.txt";
            Object confirmConversions    = Type.Missing;
            Object readOnly              = Type.Missing;
            Object addToRecentFiles      = Type.Missing;
            Object passwordDocument      = Type.Missing;
            Object passwordTemplate      = Type.Missing;
            Object revert                = Type.Missing;
            Object writePasswordDocument = Type.Missing;
            Object writePasswordTemplate = Type.Missing;
            Object format                = Type.Missing;
            Object encoding              = Microsoft.Office.Core.MsoEncoding.msoEncodingOEMCyrillicII;
            Object visible               = Type.Missing;
            Object openConflictDocument  = Type.Missing;
            Object openAndRepair         = Type.Missing;
            Object documentDirection     = Type.Missing;
            Object noEncodingDialog      = Type.Missing;

            if (!System.IO.File.Exists(filename.ToString()))
            {
                o_Word.Visible = true;
                MessageBox.Show("Файл " + filename.ToString() + " не найден.", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            o_Word.Documents.Open(ref filename,
                                  ref confirmConversions,
                                  ref readOnly,
                                  ref addToRecentFiles,
                                  ref passwordDocument,
                                  ref passwordTemplate,
                                  ref revert,
                                  ref writePasswordDocument,
                                  ref writePasswordTemplate,
                                  ref format,
                                  ref encoding,
                                  ref visible,
                                  ref openConflictDocument,
                                  ref openAndRepair,
                                  ref documentDirection,
                                  ref noEncodingDialog);

            o_Doc = o_Word.Documents.Application.ActiveDocument;
            //o_Doc.PageSetup.PaperSize = Word.WdPaperSize.wdPaperA3;
            o_Doc.PageSetup.PageWidth    = o_Word.CentimetersToPoints(29.7f);
            o_Doc.PageSetup.PageHeight   = o_Word.CentimetersToPoints(42f);
            o_Doc.PageSetup.LeftMargin   = o_Word.CentimetersToPoints(1.27f);
            o_Doc.PageSetup.RightMargin  = o_Word.CentimetersToPoints(1.27f);
            o_Doc.PageSetup.TopMargin    = o_Word.CentimetersToPoints(1.27f);
            o_Doc.PageSetup.BottomMargin = o_Word.CentimetersToPoints(1.27f);
            Word.Find      o_Find = o_Word.Selection.Find;
            Word.Selection o_Sel  = o_Word.Selection;

            o_Sel.WholeStory();
            o_Sel.Font.Size = 9;

            o_Find.ClearFormatting();
            o_Find.Replacement.ClearFormatting();
            Object p_findText = "Нереализованная отриц.";

            if (o_Find.Execute(ref p_findText,
                               MatchCase: false,
                               MatchWholeWord: false,
                               MatchWildcards: false,
                               MatchSoundsLike: Type.Missing,
                               MatchAllWordForms: false,
                               Forward: true,
                               Wrap: Type.Missing,
                               Format: false,
                               ReplaceWith: Type.Missing, Replace: Type.Missing))
            {
                o_Sel.EndKey(Unit: Word.WdUnits.wdLine, Extend: Type.Missing);
                o_Sel.HomeKey(Unit: Word.WdUnits.wdStory, Extend: Word.WdMovementType.wdExtend);
                o_Sel.Delete();
                o_Sel.Delete();
            }
            else
            {
                o_Find.ClearFormatting();
                o_Find.Replacement.ClearFormatting();
                Object s_findText = "Расходы по процентам";
                if (o_Find.Execute(ref s_findText,
                                   MatchCase: false,
                                   MatchWholeWord: false,
                                   MatchWildcards: false,
                                   MatchSoundsLike: Type.Missing,
                                   MatchAllWordForms: false,
                                   Forward: true,
                                   Wrap: Type.Missing,
                                   Format: false,
                                   ReplaceWith: Type.Missing, Replace: Type.Missing))
                {
                    o_Sel.EndKey(Unit: Word.WdUnits.wdLine, Extend: Type.Missing);
                    o_Sel.HomeKey(Unit: Word.WdUnits.wdStory, Extend: Word.WdMovementType.wdExtend);
                    o_Sel.Delete();
                    o_Sel.Delete();
                }
                else
                {
                    MessageBox.Show("Текст поиска не найден.", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    o_Word.Visible = true;
                    return;;
                }
            }

            //int pars = o_Doc.Paragraphs.Count;// узнаем количество строк в документе


            int PagesCount = o_Word.Documents.Application.ActiveDocument.Content.ComputeStatistics(Word.WdStatistic.wdStatisticPages);

            for (int i = 1; i <= PagesCount; i++)
            {
                o_Sel.GoTo(Word.WdGoToItem.wdGoToPage, Word.WdGoToDirection.wdGoToAbsolute, PagesCount, i);
                o_Sel.HomeKey(Unit: Word.WdUnits.wdLine, Extend: Type.Missing);
                o_Sel.MoveRight(Unit: Type.Missing, Count: 68, Extend: Word.WdMovementType.wdMove);
                o_Sel.ColumnSelectMode = true;
                o_Sel.MoveRight(Unit: Type.Missing, Count: 85, Extend: Word.WdMovementType.wdMove);
                o_Sel.MoveDown(Unit: Word.WdUnits.wdLine, Count: 109, Extend: Word.WdMovementType.wdMove);
                o_Sel.ColumnSelectMode = false;
                //MessageBox.Show("Остановка");
                o_Sel.Delete();
                //o_Sel.HomeKey(Unit: Word.WdUnits.wdLine, Extend: Type.Missing);
                //o_Sel.MoveDown(Unit: Word.WdUnits.wdLine, Count: 109, Extend: Type.Missing);
            }

            o_Doc.PageSetup.PageWidth  = o_Word.CentimetersToPoints(21f);
            o_Doc.PageSetup.PageHeight = o_Word.CentimetersToPoints(29.7f);
            //o_Doc.PageSetup.PaperSize = Word.WdPaperSize.wdPaperA4;
            o_Doc.PageSetup.LeftMargin = o_Word.CentimetersToPoints(2.35f);

            o_Word.ActivePrinter = n_PrintName;

            Object background           = Type.Missing;
            Object append               = Type.Missing;
            Object range                = Type.Missing;
            Object outputFileName       = Type.Missing;
            Object from                 = Type.Missing;
            Object to                   = Type.Missing;
            Object item                 = Type.Missing;
            Object copies               = Type.Missing;
            Object pages                = Type.Missing;
            Object pageType             = Type.Missing;
            Object printToFile          = Type.Missing;
            Object collate              = Type.Missing;
            Object fileName             = Type.Missing;
            Object activePrinterMacGX   = Type.Missing;
            Object manualDuplexPrint    = Type.Missing;
            Object printZoomColumn      = Type.Missing;
            Object printZoomRow         = Type.Missing;
            Object printZoomPaperWidth  = Type.Missing;
            Object printZoomPaperHeight = Type.Missing;

            o_Doc.PrintOut(ref background, ref append,
                           ref range, ref outputFileName, ref from, ref to,
                           ref item, ref copies, ref pages, ref pageType,
                           ref printToFile, ref collate, ref activePrinterMacGX,
                           ref manualDuplexPrint, ref printZoomColumn, ref printZoomRow,
                           ref printZoomPaperWidth, ref printZoomPaperHeight);

            o_Word.ActivePrinter = d_PrintName;

            Thread.Sleep(2000);

            Object saveChanges    = Word.WdSaveOptions.wdDoNotSaveChanges;
            Object originalFormat = Type.Missing;
            Object routeDocument  = Type.Missing;

            ((Word._Application)o_Word).Quit(ref saveChanges,
                                             ref originalFormat, ref routeDocument);
            o_Word = null;

            this.Cursor = Cursors.Default;
            tSSlb.Text  = "Файл " + filename + " отправлен на " + n_PrintName;
        }
Exemple #8
0
        private void GenerateDocumentButton_Click(object sender, RoutedEventArgs e)
        {
            object objMissing      = System.Reflection.Missing.Value;
            object objEndOfDocFlag = "\\endofdoc";

            Word.Application objWord = new Word.Application();
            objWord.Visible = true;
            Word.Document objDoc = objWord.Documents.Add(ref objMissing, ref objMissing, ref objMissing, ref objMissing);

            // Перший параграф, форматування
            Word.Range par1 = objDoc.Bookmarks.get_Item(ref objEndOfDocFlag).Range;
            par1.Font.Size = 14;
            par1.Font.Name = "Times New Roman";
            par1.ParagraphFormat.Alignment       = Word.WdParagraphAlignment.wdAlignParagraphJustify;
            par1.ParagraphFormat.LineSpacing     = 18;
            par1.ParagraphFormat.FirstLineIndent = objWord.InchesToPoints((float)0.0);
            par1.ParagraphFormat.SpaceAfter      = 0;
            par1.ParagraphFormat.SpaceBefore     = 0;
            // Генерація вмісту
            par1.Text = "В.4.2. Розрахунок часу на організацію наступу командиром механізованої роти (наступ)";
            par1.InsertParagraphAfter();

            // Другий параграф, форматування
            Word.Range par2 = objDoc.Bookmarks.get_Item(ref objEndOfDocFlag).Range;
            par2.Font.Size = 14;
            par2.Font.Name = "Times New Roman";
            par2.ParagraphFormat.Alignment       = Word.WdParagraphAlignment.wdAlignParagraphJustify;
            par2.ParagraphFormat.LineSpacing     = 12;
            par2.ParagraphFormat.FirstLineIndent = objWord.InchesToPoints((float)0.0);
            par2.ParagraphFormat.SpaceAfter      = 0;
            par2.ParagraphFormat.SpaceBefore     = 0;
            // Генерація вмісту
            par2.Text = "Завдання отримано о " + textBox1.Text;
            par2.InsertParagraphAfter();

            // Третій параграф, форматування
            Word.Range par3 = objDoc.Bookmarks.get_Item(ref objEndOfDocFlag).Range;
            par3.Font.Size = 14;
            par3.Font.Name = "Times New Roman";
            par3.ParagraphFormat.Alignment       = Word.WdParagraphAlignment.wdAlignParagraphJustify;
            par3.ParagraphFormat.LineSpacing     = 12;
            par3.ParagraphFormat.FirstLineIndent = objWord.InchesToPoints((float)0.0);
            par3.ParagraphFormat.SpaceAfter      = 0;
            par3.ParagraphFormat.SpaceBefore     = 0;
            // Генерація вмісту
            par3.Text = "Готовність до наступу " + textBox2.Text;
            par3.InsertParagraphAfter();

            // Четвертий параграф, форматування
            Word.Range par4 = objDoc.Bookmarks.get_Item(ref objEndOfDocFlag).Range;
            par4.Font.Size = 14;
            par4.Font.Name = "Times New Roman";
            par4.ParagraphFormat.Alignment       = Word.WdParagraphAlignment.wdAlignParagraphJustify;
            par4.ParagraphFormat.LineSpacing     = 12;
            par4.ParagraphFormat.FirstLineIndent = objWord.InchesToPoints((float)0.0);
            par4.ParagraphFormat.SpaceAfter      = 0;
            par4.ParagraphFormat.SpaceBefore     = 0;
            // Генерація вмісту
            par4.Text = "На підготовку наступу є " + textBox3.Text + " год. з них " + textBox4.Text + " год. світлого часу.";
            par4.InsertParagraphAfter();

            // П'ятий параграф, форматування
            Word.Range par5 = objDoc.Bookmarks.get_Item(ref objEndOfDocFlag).Range;
            par5.Font.Size = 14;
            par5.Font.Name = "Times New Roman";
            par5.ParagraphFormat.Alignment       = Word.WdParagraphAlignment.wdAlignParagraphJustify;
            par5.ParagraphFormat.LineSpacing     = 12;
            par5.ParagraphFormat.FirstLineIndent = objWord.InchesToPoints((float)0.0);
            par5.ParagraphFormat.SpaceAfter      = 0;
            par5.ParagraphFormat.SpaceBefore     = 0;
            // Генерація вмісту
            par5.Text = "Рішення доповісти о " + textBox5.Text;
            par5.InsertParagraphAfter();

            // Шостий параграф, форматування
            Word.Range par6 = objDoc.Bookmarks.get_Item(ref objEndOfDocFlag).Range;
            par6.Font.Size = 14;
            par6.Font.Name = "Times New Roman";
            par6.ParagraphFormat.Alignment       = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            par6.ParagraphFormat.LineSpacing     = 12;
            par6.ParagraphFormat.FirstLineIndent = objWord.InchesToPoints((float)0.0);
            par6.ParagraphFormat.SpaceAfter      = 0;
            par6.ParagraphFormat.SpaceBefore     = 0;
            // Генерація вмісту
            par6.Text = "Наявний час розподілити:\n";
            par6.InsertParagraphAfter();

            // Таблиця, форматування
            Word.Range par7 = objDoc.Bookmarks.get_Item(ref objEndOfDocFlag).Range;
            Word.Table tableObj;
            tableObj = objDoc.Tables.Add(par7, 18, 4, ref objMissing, ref objMissing);
            tableObj.Range.Font.Name = "Times New Roman";
            tableObj.Range.Font.Size = 12;
            tableObj.Range.ParagraphFormat.LineSpacing = 12;
            tableObj.Borders.InsideLineStyle           = Word.WdLineStyle.wdLineStyleSingle;
            tableObj.Borders.OutsideLineStyle          = Word.WdLineStyle.wdLineStyleSingle;

            tableObj.Cell(1, 1).Merge(tableObj.Cell(2, 1));
            tableObj.Cell(1, 2).Merge(tableObj.Cell(2, 2));
            tableObj.Cell(1, 3).Merge(tableObj.Cell(1, 4));

            tableObj.Cell(1, 1).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            tableObj.Cell(1, 1).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalTop;
            tableObj.Cell(1, 2).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            tableObj.Cell(1, 2).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalTop;
            tableObj.Cell(1, 3).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            tableObj.Cell(1, 3).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalTop;
            tableObj.Cell(2, 3).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            tableObj.Cell(2, 3).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalTop;
            tableObj.Cell(2, 4).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            tableObj.Cell(2, 4).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalTop;

            for (int i = 3; i <= 18; i++)
            {
                for (int j = 1; j <= 4; j++)
                {
                    tableObj.Cell(i, j).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
                    tableObj.Cell(i, j).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalTop;
                }
            }

            tableObj.Cell(1, 3).Range.ParagraphFormat.SpaceAfter = 8;

            // Таблиця, генерація вмісту
            tableObj.Cell(1, 1).Range.Text  = "Заходи, що проводяться";
            tableObj.Cell(1, 2).Range.Text  = "Загальна кількість часу (хв)";
            tableObj.Cell(1, 3).Range.Text  = "Час роботи";
            tableObj.Cell(2, 3).Range.Text  = "Початок\n(час, дата)";
            tableObj.Cell(2, 4).Range.Text  = "Кінець\n(час, дата)";
            tableObj.Cell(3, 1).Range.Text  = "Віддача вказівок з підготовки підрозділів до виконання бойового завдання, з організації розвідки та про час і порядок роботи на місцевості";
            tableObj.Cell(3, 2).Range.Text  = textBox6.Text;
            tableObj.Cell(3, 3).Range.Text  = textBox7.Text;
            tableObj.Cell(3, 4).Range.Text  = textBox8.Text;
            tableObj.Cell(4, 1).Range.Text  = "Проведення розрахунку часу";
            tableObj.Cell(4, 2).Range.Text  = textBox9.Text;
            tableObj.Cell(4, 3).Range.Text  = textBox10.Text;
            tableObj.Cell(4, 4).Range.Text  = textBox11.Text;
            tableObj.Cell(5, 1).Range.Text  = "Оцінка обстановки";
            tableObj.Cell(5, 2).Range.Text  = textBox12.Text;
            tableObj.Cell(5, 3).Range.Text  = textBox13.Text;
            tableObj.Cell(5, 4).Range.Text  = textBox14.Text;
            tableObj.Cell(6, 1).Range.Text  = "Прийняття рішення";
            tableObj.Cell(6, 2).Range.Text  = textBox15.Text;
            tableObj.Cell(6, 3).Range.Text  = textBox16.Text;
            tableObj.Cell(6, 4).Range.Text  = textBox17.Text;
            tableObj.Cell(7, 1).Range.Text  = "Доповідь рішення командиру батальйону";
            tableObj.Cell(7, 2).Range.Text  = textBox18.Text;
            tableObj.Cell(7, 3).Range.Text  = textBox19.Text;
            tableObj.Cell(7, 4).Range.Text  = textBox20.Text;
            tableObj.Cell(8, 1).Range.Text  = "Виїзд на рекогносцировку";
            tableObj.Cell(8, 2).Range.Text  = textBox21.Text;
            tableObj.Cell(8, 3).Range.Text  = textBox22.Text;
            tableObj.Cell(8, 4).Range.Text  = textBox23.Text;
            tableObj.Cell(9, 1).Range.Text  = "Участь у роботі на місцевості, що проводиться командиром батальйону, уточнення бойового завдання і отримання вказівок по взаємодії";
            tableObj.Cell(9, 2).Range.Text  = textBox24.Text;
            tableObj.Cell(9, 3).Range.Text  = textBox25.Text;
            tableObj.Cell(9, 4).Range.Text  = textBox26.Text;
            tableObj.Cell(10, 1).Range.Text = "Проведення рекогносцировки з командирами штатних, приданих і підтримуючих підрозділів";
            tableObj.Cell(10, 2).Range.Text = textBox27.Text;
            tableObj.Cell(10, 3).Range.Text = textBox28.Text;
            tableObj.Cell(10, 4).Range.Text = textBox29.Text;
            tableObj.Cell(11, 1).Range.Text = "Віддача бойового наказу";
            tableObj.Cell(11, 2).Range.Text = textBox30.Text;
            tableObj.Cell(11, 3).Range.Text = textBox31.Text;
            tableObj.Cell(11, 4).Range.Text = textBox32.Text;
            tableObj.Cell(12, 1).Range.Text = "Організація взаємодії та управління";
            tableObj.Cell(12, 2).Range.Text = textBox33.Text;
            tableObj.Cell(12, 3).Range.Text = textBox34.Text;
            tableObj.Cell(12, 4).Range.Text = textBox35.Text;
            tableObj.Cell(13, 1).Range.Text = "Уточнення взаємодії з командирами сусідніх рот";
            tableObj.Cell(13, 2).Range.Text = textBox36.Text;
            tableObj.Cell(13, 3).Range.Text = textBox37.Text;
            tableObj.Cell(13, 4).Range.Text = textBox38.Text;
            tableObj.Cell(14, 1).Range.Text = "Повернення командирів і робота у своїх підрозділах";
            tableObj.Cell(14, 2).Range.Text = textBox39.Text;
            tableObj.Cell(14, 3).Range.Text = textBox40.Text;
            tableObj.Cell(14, 4).Range.Text = textBox41.Text;
            tableObj.Cell(15, 1).Range.Text = "Віддача вказівок щодо всебічного забезпечення";
            tableObj.Cell(15, 2).Range.Text = textBox42.Text;
            tableObj.Cell(15, 3).Range.Text = textBox43.Text;
            tableObj.Cell(15, 4).Range.Text = textBox44.Text;
            tableObj.Cell(16, 1).Range.Text = "Контроль готовності підрозділів до виконання бойових завдань";
            tableObj.Cell(16, 2).Range.Text = textBox45.Text;
            tableObj.Cell(16, 3).Range.Text = textBox46.Text;
            tableObj.Cell(16, 4).Range.Text = textBox47.Text;
            tableObj.Cell(17, 1).Range.Text = "Доповідь командирів підрозділів про готовність до наступу";
            tableObj.Cell(17, 2).Range.Text = textBox48.Text;
            tableObj.Cell(17, 3).Range.Text = textBox49.Text;
            tableObj.Cell(17, 4).Range.Text = textBox50.Text;
            tableObj.Cell(18, 1).Range.Text = "Доповідь командиру батальйону про готовність до наступу";
            tableObj.Cell(18, 2).Range.Text = textBox51.Text;
            tableObj.Cell(18, 3).Range.Text = textBox52.Text;
            tableObj.Cell(18, 4).Range.Text = textBox53.Text;
            par7.InsertParagraphAfter();

            try
            {
                Directory.CreateDirectory(Constant.RootToSaveGenerated);
                objDoc.SaveAs($"{Constant.RootToSaveGenerated}Form 4_2 {Constant.Date}");
                string path = objDoc.FullName;

                var dialog = new DialogPrintDocument("Підтвердити друк?");
                dialog.ShowDialog();
                if (dialog.Cancelled != true)
                {
                    objDoc.PrintOut();
                }

                objDoc.Close();
                objWord.Quit();

                var order = orderService.AddOrder(path, hashService.GetHash());
                if (order != null)
                {
                    CustomMessageBox messageBox = new CustomMessageBox("Донесення занесено до бази даних!");
                    messageBox.ShowDialog();
                }
                else
                {
                    CustomMessageBox messageBox = new CustomMessageBox("Сталася помилка! Донесення не занесено до бази даних!");
                    messageBox.ShowDialog();
                }
            }
            catch (Exception ex)
            {
                CustomMessageBox messageBox = new CustomMessageBox(ex.Message);
                messageBox.ShowDialog();
            }
        }
 public void PrintPage(Word.Document doc)
 {
     Logger.Debug("SeiteDrucken wird ausgeführt.");
     doc.PrintOut(true, false, Word.WdPrintOutRange.wdPrintCurrentPage, Copies: "1", Pages: "1");
 }
Exemple #10
0
        private void GenerateDocumentButton_Click(object sender, RoutedEventArgs e)
        {
            object objMissing      = System.Reflection.Missing.Value;
            object objEndOfDocFlag = "\\endofdoc";

            Word.Application objWord = new Word.Application
            {
                Visible = true
            };
            Word.Document objDoc = objWord.Documents.Add(ref objMissing, ref objMissing, ref objMissing, ref objMissing);

            // Перший параграф, форматування
            Word.Range par1 = objDoc.Bookmarks.get_Item(ref objEndOfDocFlag).Range;
            par1.Font.Size = 14;
            par1.Font.Name = "Times New Roman";
            par1.ParagraphFormat.Alignment       = Word.WdParagraphAlignment.wdAlignParagraphJustify;
            par1.ParagraphFormat.LineSpacing     = 18;
            par1.ParagraphFormat.FirstLineIndent = objWord.InchesToPoints((float)0.0);
            par1.ParagraphFormat.SpaceAfter      = 0;
            par1.ParagraphFormat.SpaceBefore     = 0;
            // Генерація вмісту
            par1.Text = "В.3.2. Розрахунок часу роботи командира механізованого батальйону (оборона)";
            par1.InsertParagraphAfter();

            // Другий параграф, форматування
            Word.Range par2 = objDoc.Bookmarks.get_Item(ref objEndOfDocFlag).Range;
            par2.Font.Size = 14;
            par2.Font.Name = "Times New Roman";
            par2.ParagraphFormat.Alignment       = Word.WdParagraphAlignment.wdAlignParagraphJustify;
            par2.ParagraphFormat.LineSpacing     = 18;
            par2.ParagraphFormat.FirstLineIndent = objWord.InchesToPoints((float)0.0);
            par2.ParagraphFormat.SpaceAfter      = 0;
            par2.ParagraphFormat.SpaceBefore     = 0;
            // Генерація вмісту
            par2.Text = "Час отримання завдання: " + textBox1.Text + ".";
            par2.InsertParagraphAfter();

            // Третій параграф, форматування
            Word.Range par3 = objDoc.Bookmarks.get_Item(ref objEndOfDocFlag).Range;
            par3.Font.Size = 14;
            par3.Font.Name = "Times New Roman";
            par3.ParagraphFormat.Alignment       = Word.WdParagraphAlignment.wdAlignParagraphJustify;
            par3.ParagraphFormat.LineSpacing     = 18;
            par3.ParagraphFormat.FirstLineIndent = objWord.InchesToPoints((float)0.0);
            par3.ParagraphFormat.SpaceAfter      = 0;
            par3.ParagraphFormat.SpaceBefore     = 0;
            // Генерація вмісту
            par3.Text = "Час готовності: " + textBox2.Text + ".";
            par3.InsertParagraphAfter();

            // Четвертий параграф, форматування
            Word.Range par4 = objDoc.Bookmarks.get_Item(ref objEndOfDocFlag).Range;
            par4.Font.Size = 14;
            par4.Font.Name = "Times New Roman";
            par4.ParagraphFormat.Alignment       = Word.WdParagraphAlignment.wdAlignParagraphJustify;
            par4.ParagraphFormat.LineSpacing     = 18;
            par4.ParagraphFormat.FirstLineIndent = objWord.InchesToPoints((float)0.0);
            par4.ParagraphFormat.SpaceAfter      = 0;
            par4.ParagraphFormat.SpaceBefore     = 0;
            // Генерація вмісту
            par4.Text = "Загальний час для підготовки підрозділів: " + textBox3.Text + ".";
            par4.InsertParagraphAfter();

            // П'ятий параграф, форматування
            Word.Range par5 = objDoc.Bookmarks.get_Item(ref objEndOfDocFlag).Range;
            par5.Font.Size = 14;
            par5.Font.Name = "Times New Roman";
            par5.ParagraphFormat.Alignment       = Word.WdParagraphAlignment.wdAlignParagraphJustify;
            par5.ParagraphFormat.LineSpacing     = 18;
            par5.ParagraphFormat.FirstLineIndent = objWord.InchesToPoints((float)0.0);
            par5.ParagraphFormat.SpaceAfter      = 0;
            par5.ParagraphFormat.SpaceBefore     = 0;
            // Генерація вмісту
            par5.Text = "Кількість світлого часу доби: " + textBox4.Text + ".";
            par5.InsertParagraphAfter();

            // Шостий параграф, форматування
            Word.Range par6 = objDoc.Bookmarks.get_Item(ref objEndOfDocFlag).Range;
            par6.Font.Size = 14;
            par6.Font.Name = "Times New Roman";
            par6.ParagraphFormat.Alignment       = Word.WdParagraphAlignment.wdAlignParagraphJustify;
            par6.ParagraphFormat.LineSpacing     = 18;
            par6.ParagraphFormat.FirstLineIndent = objWord.InchesToPoints((float)0.0);
            par6.ParagraphFormat.SpaceAfter      = 0;
            par6.ParagraphFormat.SpaceBefore     = 0;
            // Генерація вмісту
            par6.Text = "Кількість темного часу доби: " + textBox5.Text + ".";
            par6.InsertParagraphAfter();

            // Сьомий параграф, форматування
            Word.Range par7 = objDoc.Bookmarks.get_Item(ref objEndOfDocFlag).Range;
            par7.Font.Size = 14;
            par7.Font.Name = "Times New Roman";
            par7.ParagraphFormat.Alignment       = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            par7.ParagraphFormat.LineSpacing     = 12;
            par7.ParagraphFormat.FirstLineIndent = objWord.InchesToPoints((float)0.0);
            par7.ParagraphFormat.SpaceAfter      = 1;
            // Генерація вмісту
            par7.Text = "Наявний час розподілити";
            par7.InsertParagraphAfter();

            // Таблиця, форматування
            Word.Range par8 = objDoc.Bookmarks.get_Item(ref objEndOfDocFlag).Range;
            Word.Table tableObj;
            tableObj = objDoc.Tables.Add(par8, 18, 4, ref objMissing, ref objMissing);
            tableObj.Range.Font.Name = "Times New Roman";
            tableObj.Range.Font.Size = 12;
            tableObj.Range.ParagraphFormat.LineSpacing = 12;
            tableObj.Borders.InsideLineStyle           = Word.WdLineStyle.wdLineStyleSingle;
            tableObj.Borders.OutsideLineStyle          = Word.WdLineStyle.wdLineStyleSingle;

            tableObj.Cell(1, 1).Merge(tableObj.Cell(2, 1));
            tableObj.Cell(1, 2).Merge(tableObj.Cell(2, 2));
            tableObj.Cell(1, 3).Merge(tableObj.Cell(1, 4));

            tableObj.Cell(1, 1).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            tableObj.Cell(1, 1).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalTop;
            tableObj.Cell(1, 2).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            tableObj.Cell(1, 2).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalTop;
            tableObj.Cell(1, 3).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            tableObj.Cell(1, 3).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalTop;
            tableObj.Cell(2, 3).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            tableObj.Cell(2, 3).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalTop;
            tableObj.Cell(2, 4).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            tableObj.Cell(2, 4).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalTop;

            for (int i = 3; i <= 18; i++)
            {
                tableObj.Cell(i, 1).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft;
                tableObj.Cell(i, 1).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalTop;
            }

            for (int i = 3; i <= 18; i++)
            {
                for (int j = 2; j <= 4; j++)
                {
                    tableObj.Cell(i, j).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
                    tableObj.Cell(i, j).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalTop;
                }
            }

            tableObj.Cell(1, 3).Range.ParagraphFormat.SpaceAfter = 8;

            // Таблиця, генерація вмісту
            tableObj.Cell(1, 1).Range.Text  = "Заходи, що проводяться";
            tableObj.Cell(1, 2).Range.Text  = "Загальна кількість часу (хв)";
            tableObj.Cell(1, 3).Range.Text  = "Час роботи";
            tableObj.Cell(2, 3).Range.Text  = "Початок\n(час, дата)";
            tableObj.Cell(2, 4).Range.Text  = "Кінець\n(час, дата)";
            tableObj.Cell(3, 1).Range.Text  = "З’ясування завдання";
            tableObj.Cell(3, 2).Range.Text  = textBox6.Text;
            tableObj.Cell(3, 3).Range.Text  = textBox7.Text;
            tableObj.Cell(3, 4).Range.Text  = textBox8.Text;
            tableObj.Cell(4, 1).Range.Text  = "Визначення заходів, які необхідно провести негайно для підготовки батальйону до бою";
            tableObj.Cell(4, 2).Range.Text  = textBox9.Text;
            tableObj.Cell(4, 3).Range.Text  = textBox10.Text;
            tableObj.Cell(4, 4).Range.Text  = textBox11.Text;
            tableObj.Cell(5, 1).Range.Text  = "Відпрацювання розрахунку часу";
            tableObj.Cell(5, 2).Range.Text  = textBox12.Text;
            tableObj.Cell(5, 3).Range.Text  = textBox13.Text;
            tableObj.Cell(5, 4).Range.Text  = textBox14.Text;
            tableObj.Cell(6, 1).Range.Text  = "Оцінка обстановки";
            tableObj.Cell(6, 2).Range.Text  = textBox15.Text;
            tableObj.Cell(6, 3).Range.Text  = textBox16.Text;
            tableObj.Cell(6, 4).Range.Text  = textBox17.Text;
            tableObj.Cell(7, 1).Range.Text  = "Прийняття рішення";
            tableObj.Cell(7, 2).Range.Text  = textBox18.Text;
            tableObj.Cell(7, 3).Range.Text  = textBox19.Text;
            tableObj.Cell(7, 4).Range.Text  = textBox20.Text;
            tableObj.Cell(8, 1).Range.Text  = "Доповідь рішення командиру омбр";
            tableObj.Cell(8, 2).Range.Text  = textBox21.Text;
            tableObj.Cell(8, 3).Range.Text  = textBox22.Text;
            tableObj.Cell(8, 4).Range.Text  = textBox23.Text;
            tableObj.Cell(9, 1).Range.Text  = "Проведення рекогносцировки";
            tableObj.Cell(9, 2).Range.Text  = textBox24.Text;
            tableObj.Cell(9, 3).Range.Text  = textBox25.Text;
            tableObj.Cell(9, 4).Range.Text  = textBox26.Text;
            tableObj.Cell(10, 1).Range.Text = "Віддання бойового наказу";
            tableObj.Cell(10, 2).Range.Text = textBox27.Text;
            tableObj.Cell(10, 3).Range.Text = textBox28.Text;
            tableObj.Cell(10, 4).Range.Text = textBox29.Text;
            tableObj.Cell(11, 1).Range.Text = "Організація взаємодії і системи вогню та віддання вказівок, щодо всебічного забезпечення";
            tableObj.Cell(11, 2).Range.Text = textBox30.Text;
            tableObj.Cell(11, 3).Range.Text = textBox31.Text;
            tableObj.Cell(11, 4).Range.Text = textBox32.Text;
            tableObj.Cell(12, 1).Range.Text = "Заняття району оборони батальйону";
            tableObj.Cell(12, 2).Range.Text = textBox33.Text;
            tableObj.Cell(12, 3).Range.Text = textBox34.Text;
            tableObj.Cell(12, 4).Range.Text = textBox35.Text;
            tableObj.Cell(13, 1).Range.Text = "Доповідь командиру омбр про готовність системи вогню";
            tableObj.Cell(13, 2).Range.Text = textBox36.Text;
            tableObj.Cell(13, 3).Range.Text = textBox37.Text;
            tableObj.Cell(13, 4).Range.Text = textBox38.Text;
            tableObj.Cell(14, 1).Range.Text = "Виконання робіт інженерного обладнання РОБ 1 черги";
            tableObj.Cell(14, 2).Range.Text = textBox39.Text;
            tableObj.Cell(14, 3).Range.Text = textBox40.Text;
            tableObj.Cell(14, 4).Range.Text = textBox41.Text;
            tableObj.Cell(15, 1).Range.Text = "Виконання робіт 2 черги інженерного обладнання РОБ";
            tableObj.Cell(15, 2).Range.Text = textBox42.Text;
            tableObj.Cell(15, 3).Range.Text = textBox43.Text;
            tableObj.Cell(15, 4).Range.Text = textBox44.Text;
            tableObj.Cell(16, 1).Range.Text = "Контроль та допомога командирам підрозділів в організації оборони";
            tableObj.Cell(16, 2).Range.Text = textBox45.Text;
            tableObj.Cell(16, 3).Range.Text = textBox46.Text;
            tableObj.Cell(16, 4).Range.Text = textBox47.Text;
            tableObj.Cell(17, 1).Range.Text = "Прийняття доповіді командирів підрозділів про готовність оборони";
            tableObj.Cell(17, 2).Range.Text = textBox48.Text;
            tableObj.Cell(17, 3).Range.Text = textBox49.Text;
            tableObj.Cell(17, 4).Range.Text = textBox50.Text;
            tableObj.Cell(18, 1).Range.Text = "Доповідь командиру омбр про готовність оборони";
            tableObj.Cell(18, 2).Range.Text = textBox51.Text;
            tableObj.Cell(18, 3).Range.Text = textBox52.Text;
            tableObj.Cell(18, 4).Range.Text = textBox53.Text;
            par8.InsertParagraphAfter();

            // Дев'ятий параграф форматування
            Word.Range par9 = objDoc.Bookmarks.get_Item(ref objEndOfDocFlag).Range;
            par9.Font.Size = 14;
            par9.Font.Name = "Times New Roman";
            par9.ParagraphFormat.Alignment       = Word.WdParagraphAlignment.wdAlignParagraphJustify;
            par9.ParagraphFormat.LineSpacing     = 18;
            par9.ParagraphFormat.FirstLineIndent = objWord.InchesToPoints((float)0.0);
            par9.ParagraphFormat.SpaceBefore     = 20;
            // Генерація вмісту
            par9.Text = "Начальник штабу " + textBox54.Text + " мб";
            par9.InsertParagraphAfter();

            try
            {
                Directory.CreateDirectory(Constant.RootToSaveGenerated);
                objDoc.SaveAs($"{Constant.RootToSaveGenerated}Form 3_2 {Constant.Date}");
                string path = objDoc.FullName;

                var dialog = new DialogPrintDocument("Підтвердити друк?");
                dialog.ShowDialog();
                if (dialog.Cancelled != true)
                {
                    objDoc.PrintOut();
                }

                objDoc.Close();
                objWord.Quit();

                var order = orderService.AddOrder(path, hashService.GetHash());
                if (order != null)
                {
                    CustomMessageBox messageBox = new CustomMessageBox("Донесення занесено до бази даних!");
                    messageBox.ShowDialog();
                }
                else
                {
                    CustomMessageBox messageBox = new CustomMessageBox("Сталася помилка! Донесення не занесено до бази даних!");
                    messageBox.ShowDialog();
                }
            }
            catch (Exception ex)
            {
                CustomMessageBox messageBox = new CustomMessageBox(ex.Message);
                messageBox.ShowDialog();
            }
        }
Exemple #11
0
        private void btnGenerate_Click(object sender, EventArgs e)
        {
            if (lstTicket == null || lstTicket.Count == 0)
            {
                MessageBox.Show("Please search ticket order first", "Disneyland", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            string tempPath = Application.StartupPath + $@"\TicketTemplate\{order.OrderId}";

            Word.Application wapp = new Word.Application();
            wapp.Visible = false;
            if (Directory.Exists(tempPath))
            {
                var files = Directory.GetFiles(tempPath);
                for (int i = 0; i < files.Length; i++)
                {
                    File.Delete(files[i]);
                }
                Directory.Delete(tempPath);
            }
            Directory.CreateDirectory(tempPath);

            lstTicket.ForEach(x =>
            {
                Word.Document ticketDoc = wapp.Documents.Open(Application.StartupPath + @"\ticketTemp.dotm");
                ticketDoc.Bookmarks["date"].Range.Text             = x.InvalidDate.ToString("yyyy-MMdd");
                ticketDoc.Bookmarks["dateType"].Range.Text         = x.TicketOffer.TicketName.Contains("年票") ? "有效" : "入園";
                ticketDoc.Bookmarks["name"].Range.Text             = x.GuestName;
                ticketDoc.Bookmarks["price"].Range.Text            = x.TicketOffer.Price.ToString();
                ticketDoc.Bookmarks["ticketId"].Range.Text         = x.TicketId;
                ticketDoc.Bookmarks["ticketType"].Range.Font.Color = x.TicketOffer.TicketName.Contains("年票") ? Word.WdColor.wdColorRed : Word.WdColor.wdColorBlue;
                ticketDoc.Bookmarks["ticketType"].Range.Text       = x.TicketOffer.TicketName.Contains("年票") ? "年票 Annual Pass" : "一日票 One Day Pass";
                ticketDoc.Bookmarks["type"].Range.Text             = x.TicketOffer.TicketName;

                Bitmap qrCode = QRCode.Generate(CreateCode(x), 100, 100);
                Clipboard.SetImage(qrCode);
                ticketDoc.Bookmarks["image"].Range.Paste();
                Clipboard.Clear();
                ticketDoc.SaveAs2(tempPath + $@"\{x.TicketId}.docx", Word.WdSaveFormat.wdFormatDocumentDefault);
                ticketDoc.Close(false);
            });

            var lstFile = Directory.GetFiles(tempPath);

            Word.Document mainDoc = new Word.Document();
            for (int i = 0; i < lstFile.Length; i++)
            {
                if (i % 5 == 0)
                {
                    mainDoc = wapp.Documents.Add();
                }

                Word.Paragraph paragraph = mainDoc.Paragraphs.Add();
                paragraph.Range.InsertFile(lstFile[i]);
                paragraph.Range.Delete();

                if (i == lstFile.Length - 1 || i % 5 == 4)
                {
                    //mainDoc.SaveAs2(tempPath + $@"\{(int)(i / 5) + 1}.pdf", Word.WdSaveFormat.wdFormatPDF);
                    mainDoc.PrintOut(false);
                    mainDoc.Close(false);
                }
            }


            wapp.Quit(false);
        }
Exemple #12
0
        private void printmotalba(object filename, object savaAs)
        {
            foreach (var process in Process.GetProcessesByName("WINWORD"))
            {
                process.Kill();
            }
            object missing = Missing.Value;

            Word.Application wordApp = new Word.Application();

            Word.Document aDoc = null;

            if (File.Exists((string)filename))
            {
                object readOnly  = false; //default
                object isVisible = false;

                wordApp.Visible = false;

                aDoc = wordApp.Documents.Open(ref filename, ref missing, ref readOnly,
                                              ref missing, ref missing, ref missing,
                                              ref missing, ref missing, ref missing,
                                              ref missing, ref missing, ref missing,
                                              ref missing, ref missing, ref missing, ref missing);
                FindAndReplace(wordApp, "<date>", date.Text);
                FindAndReplace(wordApp, "<pay>", pay.Text);
                FindAndReplace(wordApp, "<name>", user.Text);



                aDoc.PageSetup.Orientation = Word.WdOrientation.wdOrientPortrait;
                aDoc.Activate();

                //Find and replace:

                object copies   = "1";
                object pages    = "";
                object range    = Word.WdPrintOutRange.wdPrintAllDocument;
                object items    = Word.WdPrintOutItem.wdPrintDocumentContent;
                object pageType = Word.WdPrintOutPages.wdPrintAllPages;
                object oTrue    = true;
                object oFalse   = false;
                object oMissing = Missing.Value;
                time_now.Text = "الحالة : " + "جارى طباعة الإيصال";
                aDoc.PrintOut(ref oTrue, ref oFalse, ref range, ref oMissing, ref oMissing, ref oMissing, ref items, ref copies, ref pages, ref pageType, ref oFalse, ref oTrue, ref oMissing, ref oFalse, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
                //Close Document:
                time_now.Text = "الحالة : " + "تمت الطباعة";
                aDoc.SaveAs2(savaAs);
                aDoc.Close(ref missing, ref missing, ref missing);
                foreach (var process in Process.GetProcessesByName("WINWORD"))
                {
                    process.Kill();
                }
            }
            else
            {
                MessageBox.Show("file dose not exist.");
                return;
            }
            time_now.Text = "الحالة : " + "متصل";
        }
 /// <summary>
 /// Печать документа
 /// </summary>
 public void ReportPrinting()
 {
     WordDoc.PrintOut();
 }
Exemple #14
0
        //</Snippet106>


        //---------------------------------------------------------------------
        private void Test15()
        {
            //<Snippet14>
            Application.PrintPreview = true;
            //</Snippet14>


            //<Snippet12>
            object copies   = "1";
            object pages    = "1";
            object range    = Word.WdPrintOutRange.wdPrintCurrentPage;
            object items    = Word.WdPrintOutItem.wdPrintDocumentContent;
            object pageType = Word.WdPrintOutPages.wdPrintAllPages;
            object oTrue    = true;
            object oFalse   = false;

            Word.Document document = this.Application.ActiveDocument;

            document.PrintOut(
                ref oTrue, ref oFalse, ref range, ref missing, ref missing, ref missing,
                ref items, ref copies, ref pages, ref pageType, ref oFalse, ref oTrue,
                ref missing, ref oFalse, ref missing, ref missing, ref missing, ref missing);
            //</Snippet12>


            //<Snippet10>
            object fileName = @"C:\Test\NewDocument.docx";

            this.Application.ActiveDocument.SaveAs(ref fileName,
                                                   ref missing, ref missing, ref missing, ref missing, ref missing,
                                                   ref missing, ref missing, ref missing, ref missing, ref missing,
                                                   ref missing, ref missing, ref missing, ref missing, ref missing);
            //</Snippet10>


            //<Snippet120>
            this.Application.ActiveDocument.Paragraphs[1].Range.Select();
            //</Snippet120>


            //<Snippet119>
            this.Application.ActiveDocument.DeleteAllComments();
            //</Snippet119>


            //<Snippet118>
            object text = "Add a comment to the first paragraph.";

            this.Application.ActiveDocument.Comments.Add(
                this.Application.ActiveDocument.Paragraphs[1].Range, ref text);
            //</Snippet118>


            //<Snippet116>
            foreach (Word.Section section in this.Application.ActiveDocument.Sections)
            {
                Word.Range headerRange = section.Headers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
                headerRange.Fields.Add(headerRange, Word.WdFieldType.wdFieldPage);
                headerRange.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight;
            }
            //</Snippet116>
        }