SlideShare a Scribd company logo
1 of 6
private void CriarDocWord()
        {
            object oRng;
            object oMissing = System.Reflection.Missing.Value;
            object oEndOfDoc = "endofdoc"; /* endofdoc is a predefined
bookmark */

            Word._Application WORD;
            Word._Document oDoc;
            WORD = new Word.Application();
            WORD.Visible = false;
            oDoc = WORD.Documents.Add(ref oMissing, ref oMissing,
                ref oMissing, ref oMissing);

            //Insert a paragraph at the beginning of the document.
            Word.Paragraph Nome;
            Nome = oDoc.Content.Paragraphs.Add(ref oMissing);
            Nome.Range.Font.Bold = 1;
            Nome.Format.SpaceBefore = 10;
            Nome.Format.SpaceAfter = 24;    //24 pt spacing after paragraph.
            Nome.Range.InsertParagraphAfter();

            //banco--------------------------------------------
            OdbcConnection conexao = new OdbcConnection(strConex);
            conexao.Open();
            OdbcCommand cSQL = new OdbcCommand("select nm_prato from prato where
cd_prato =" + cboCodigo.Text, conexao);
            OdbcDataReader dados = cSQL.ExecuteReader();
            string nomeprato = "";
            if (dados.HasRows)
                while (dados.Read())
                {
                    Nome.Range.Text = "PRATO: " + dados[0].ToString();
            Nome.Range.Paragraphs.Alignment =
Word.WdParagraphAlignment.wdAlignParagraphLeft;
             nomeprato = dados[0].ToString();
        }
            dados.Close();
            conexao.Close();
            dados.Dispose();
            conexao.Dispose();

            Word.Paragraph TEMPO;
            oRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
            TEMPO = oDoc.Content.Paragraphs.Add(ref oRng);
            TEMPO.Range.Font.Bold = 1;
            TEMPO.Format.SpaceAfter = 6;
            TEMPO.Range.InsertParagraphAfter();

            conexao = new OdbcConnection(strConex);
            conexao.Open();
            cSQL = new OdbcCommand("select hr_preparo from prato where cd_prato
=" + cboCodigo.Text, conexao);
            dados = cSQL.ExecuteReader();
            if (dados.HasRows)
                while (dados.Read())
                    TEMPO.Range.Text = "TEMPO DE PREPARO: " +
dados[0].ToString() + " Minutos";
            TEMPO.Range.Paragraphs.Alignment =
Word.WdParagraphAlignment.wdAlignParagraphLeft;
            dados.Close();
            conexao.Close();
            dados.Dispose();
            conexao.Dispose();
Word.Paragraph RENDIMENTO;
            oRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;

            RENDIMENTO = oDoc.Content.Paragraphs.Add(ref oRng);
            RENDIMENTO.Range.Font.Bold = 1;
            RENDIMENTO.Format.SpaceAfter = 6;
            RENDIMENTO.Range.InsertParagraphAfter();

            conexao = new OdbcConnection(strConex);
            conexao.Open();
            cSQL = new OdbcCommand("select qt_serve from prato where cd_prato ="
+ cboCodigo.Text, conexao);
            dados = cSQL.ExecuteReader();
            if (dados.HasRows)
                while (dados.Read())
                    RENDIMENTO.Range.Text = "RENDIMENTO : " +
dados[0].ToString() + "    Pessoas";
            RENDIMENTO.Range.Paragraphs.Alignment =
Word.WdParagraphAlignment.wdAlignParagraphLeft;
            dados.Close();
            conexao.Close();
            dados.Dispose();
            conexao.Dispose();

            Word.Paragraph UTENSILIOS;
            oRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;

            UTENSILIOS = oDoc.Content.Paragraphs.Add(ref oRng);
            UTENSILIOS.Range.Font.Bold = 1;
            UTENSILIOS.Format.SpaceAfter = 6;
            UTENSILIOS.Range.InsertParagraphAfter();

            conexao = new OdbcConnection(strConex);
            conexao.Open();
            cSQL = new OdbcCommand("select ds_utensilio from prato where
cd_prato =" + cboCodigo.Text, conexao);
            dados = cSQL.ExecuteReader();
            if (dados.HasRows)
                while (dados.Read())
                    UTENSILIOS.Range.Text = " UTENSÍLIOS E EQUIPAMENTOS : " +
dados[0].ToString() + "    Pessoas";
            UTENSILIOS.Range.Paragraphs.Alignment =
Word.WdParagraphAlignment.wdAlignParagraphLeft;
            dados.Close();
            conexao.Close();
            dados.Dispose();
            conexao.Dispose();

            Word.Table oTable;
            Word.Range wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
            oTable = oDoc.Tables.Add(wrdRng, listBox1.Items.Count + 4, 5, ref
oMissing, ref oMissing);
            oTable.Range.ParagraphFormat.SpaceAfter = 6;
            oTable.Cell(1, 1).Range.Text = "PRODUTO";
            oTable.Cell(1, 2).Range.Text = "PESO BRUTO";
            oTable.Cell(1, 3).Range.Text = "PESO LÍQUIDO";
            oTable.Cell(1, 4).Range.Text = "IPC";
            oTable.Cell(1, 5).Range.Text = "VALOR UNITÁRIO";
            listBox1.Items.Clear();
            listBox2.Items.Clear();
            listBox3.Items.Clear();
            listBox4.Items.Clear();
            listBox5.Items.Clear();
string c = "";
            x = 2;
            comando = "SELECT m.nm_materia_prima INGREDIENTE,i.qt_materia_prima
QTDE,truncate( ((i.qt_materia_prima)-( ( ((m.qt_ipc_materia_prima -1) *100)
* i.qt_materia_prima ) /100)),3),
m.qt_ipc_materia_prima,m.vl_unitario_materia_prima AS 'VALOR UNITARIO'";
            comando += " from materia_prima m join ingrediente_receita i";
            comando += " on (i.cd_materia_prima=m.cd_materia_prima)";
            comando += " join unidade_medida u on
(u.cd_unidade_medida=i.cd_unidade_medida)";
            comando += " where i.cd_prato=" + cboCodigo.Text;
            Insere(comando);
            double total = 0;
            int _i;
            for (int i = 2; i <= listBox1.Items.Count + 1; i++)
            {
                _i = i - 2;
                string aa = listBox1.Items[_i].ToString(),
               bb = listBox2.Items[_i].ToString(),
               cc = listBox3.Items[_i].ToString(),
               dd = listBox4.Items[_i].ToString(),
               ee = listBox5.Items[_i].ToString();
                aa = aa.Replace(",", ".");
                bb = bb.Replace(",", ".");
                cc = cc.Replace(",", ".");
                dd = dd.Replace(",", ".");
                ee = ee.Replace(",", ".");
                oTable.Cell(i, 1).Range.Text = aa;
                oTable.Cell(i, 2).Range.Text = bb;
                oTable.Cell(i, 3).Range.Text = cc;
                oTable.Cell(i, 4).Range.Text = dd;
                oTable.Cell(i, 5).Range.Text = ee;
            }

            oTable.Rows[1].Range.Font.Bold = 1;
            oTable.Rows[1].Range.Font.Italic = 1;
            WORD.Selection.TypeParagraph();
            Word.Paragraph modo_preparo;
            oRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
            modo_preparo = oDoc.Content.Paragraphs.Add(ref oRng);
            modo_preparo.Format.SpaceAfter = 10;
            modo_preparo.Range.Font.Bold = 1;
            modo_preparo.Range.InsertParagraphAfter();
            conexao = new OdbcConnection(strConex);
            conexao.Open();
            cSQL = new OdbcCommand("select ds_modo_preparo from prato where
cd_prato =" + cboCodigo.Text, conexao);
            dados = cSQL.ExecuteReader();
            if (dados.HasRows)
                while (dados.Read())
                     modo_preparo.Range.Text = "MODO DE PREPARO: " +
dados[0].ToString();
            dados.Close();
            conexao.Close();
            dados.Dispose();
            conexao.Dispose();

            Word.Paragraph valor_prato;
            oRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
            valor_prato = oDoc.Content.Paragraphs.Add(ref oRng);
            valor_prato.Format.SpaceAfter = 20;
            valor_prato.Range.Font.Bold = 1;
            valor_prato.Range.InsertParagraphAfter();
            conexao = new OdbcConnection(strConex);
conexao.Open();
            cSQL = new OdbcCommand("select vl_prato from prato where cd_prato ="
+ cboCodigo.Text, conexao);
            dados = cSQL.ExecuteReader();
            if (dados.HasRows)
                while (dados.Read())
                    valor_prato.Range.Text = "VALOR : " + dados[0].ToString();
            valor_prato.Range.Paragraphs.Alignment =
Word.WdParagraphAlignment.wdAlignParagraphRight;
            dados.Close();
            conexao.Close();
            dados.Dispose();
            conexao.Dispose();

            Word.Paragraph valor_sugerido;
            oRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
            valor_sugerido = oDoc.Content.Paragraphs.Add(ref oRng);
            valor_sugerido.Format.SpaceAfter = 20;
            valor_sugerido.Range.Font.Bold = 1;
            valor_sugerido.Range.InsertParagraphAfter();
            conexao = new OdbcConnection(strConex);
            conexao.Open(); string
                conta = "SELECT truncate( sum((i.qt_materia_prima *
m.vl_unitario_materia_prima)/1000),2) from materia_prima m join
ingrediente_receita i ";
                conta += "on (m.cd_materia_prima = i.cd_materia_prima) where
i.cd_prato =" + cboCodigo.Text;
            cSQL = new OdbcCommand(conta,conexao);
            dados = cSQL.ExecuteReader();
            if (dados.HasRows)
                while (dados.Read())
                     valor_sugerido.Range.Text = "PREÇO SUGERIDO : " +
dados[0].ToString();
            valor_sugerido.Range.Paragraphs.Alignment =
Word.WdParagraphAlignment.wdAlignParagraphRight;
            dados.Close();
            conexao.Close();
            dados.Dispose();
            conexao.Dispose();

            try
            {
                conexao = new OdbcConnection(strConex);
                conexao.Open();
                cSQL = new OdbcCommand("select nm_imagem_prato from prato where
cd_prato =" + cboCodigo.Text, conexao);
                dados = cSQL.ExecuteReader();
                if (dados.HasRows)
                    while (dados.Read())
                        oRng =
oDoc.Application.Selection.InlineShapes.AddPicture(dados[0].ToString()).ScaleHei
ght = 30;
                oRng = oDoc.Application.Selection.Paragraphs.Alignment =
Word.WdParagraphAlignment.wdAlignParagraphCenter;
                dados.Close();
                conexao.Close();
                dados.Dispose();
                conexao.Dispose();
            }
            catch
            {

            }
            WORD.Selection.TypeParagraph();
WORD.Selection.TypeParagraph();
            //SALVAR
            oDoc.SaveAs(Application.StartupPath.Substring(0,
Application.StartupPath.Length - 10) + "Documentos
Temporarios"+nomeprato+".docx" );

              oDoc.Close(ref oMissing, ref oMissing, ref oMissing);
              WORD.Quit(ref oMissing, ref oMissing, ref oMissing);
              oDoc = null;
              WORD = null;

                                                 // Converte para PDF
            // Create a new Microsoft Word application object
            Microsoft.Office.Interop.Word.Application word = new
Microsoft.Office.Interop.Word.Application();

              // C# doesn't have optional arguments so we'll need a dummy value
              object oMissing1 = System.Reflection.Missing.Value;

            // Get list of Word files in specified directory
            DirectoryInfo dirInfo = new
DirectoryInfo(Application.StartupPath.Substring(0,
Application.StartupPath.Length - 10) + "Documentos Temporarios");
            FileInfo[] wordFiles = dirInfo.GetFiles("*.docx");

              word.Visible = false;
              word.ScreenUpdating = false;
              foreach (FileInfo wordFile in wordFiles)
              {
                  // Cast as Object for word Open method
                  Object filename = (Object)wordFile.FullName;

                  // Use the dummy value as a placeholder for optional arguments
                  Word.Document doc = word.Documents.Open(ref filename, ref
oMissing1,
                      ref oMissing1, ref oMissing1, ref oMissing1, ref oMissing1,
ref oMissing1,
                      ref oMissing1, ref oMissing1, ref oMissing1, ref oMissing1,
ref oMissing1,
                      ref oMissing1, ref oMissing1, ref oMissing1, ref oMissing1);
                  doc.Activate();

                  object outputFileName = wordFile.FullName.Replace(".docx",
".pdf");
                  object fileFormat = Word.WdSaveFormat.wdFormatPDF;

                  // Save document into PDF Format
                  doc.SaveAs(ref outputFileName,
                      ref fileFormat, ref oMissing1, ref oMissing1,
                      ref oMissing1, ref oMissing1, ref oMissing1, ref oMissing1,
                      ref oMissing1, ref oMissing1, ref oMissing1, ref oMissing1,
                      ref oMissing1, ref oMissing1, ref oMissing1, ref oMissing1);

                  // Close the Word document, but leave the Word application open.
                  // doc has to be cast to type _Document so that it will find the
                  // correct Close method.
                  object saveChanges = Word.WdSaveOptions.wdDoNotSaveChanges;
                  ((Word.Document)doc).Close(ref saveChanges, ref oMissing1, ref
oMissing1);
                  doc = null;
              }

              // word has to be cast to type _Application so that it will find
              // the correct Quit method.
((Word.Application)word).Quit(ref oMissing1, ref oMissing1, ref
oMissing1);
              word = null;

System.Diagnostics.Process.Start(Application.StartupPath.Substring(0,
Application.StartupPath.Length - 10) + "Documentos Temporarios" + nomeprato
+ ".pdf");

More Related Content

What's hot

MongoDB and Indexes - MUG Denver - 20160329
MongoDB and Indexes - MUG Denver - 20160329MongoDB and Indexes - MUG Denver - 20160329
MongoDB and Indexes - MUG Denver - 20160329Douglas Duncan
 
MongoDB - Aggregation Pipeline
MongoDB - Aggregation PipelineMongoDB - Aggregation Pipeline
MongoDB - Aggregation PipelineJason Terpko
 
Fast querying indexing for performance (4)
Fast querying   indexing for performance (4)Fast querying   indexing for performance (4)
Fast querying indexing for performance (4)MongoDB
 
[제1회 루씬 한글분석기 기술세미나] solr로 나만의 검색엔진을 만들어보자
[제1회 루씬 한글분석기 기술세미나] solr로 나만의 검색엔진을 만들어보자[제1회 루씬 한글분석기 기술세미나] solr로 나만의 검색엔진을 만들어보자
[제1회 루씬 한글분석기 기술세미나] solr로 나만의 검색엔진을 만들어보자Donghyeok Kang
 
MongoDB Days Silicon Valley: MongoDB and the Hadoop Connector
MongoDB Days Silicon Valley: MongoDB and the Hadoop ConnectorMongoDB Days Silicon Valley: MongoDB and the Hadoop Connector
MongoDB Days Silicon Valley: MongoDB and the Hadoop ConnectorMongoDB
 
MongoDB Performance Tuning
MongoDB Performance TuningMongoDB Performance Tuning
MongoDB Performance TuningPuneet Behl
 
Query for json databases
Query for json databasesQuery for json databases
Query for json databasesBinh Le
 
Indexing and Query Optimizer (Mongo Austin)
Indexing and Query Optimizer (Mongo Austin)Indexing and Query Optimizer (Mongo Austin)
Indexing and Query Optimizer (Mongo Austin)MongoDB
 
20110514 mongo dbチューニング
20110514 mongo dbチューニング20110514 mongo dbチューニング
20110514 mongo dbチューニングYuichi Matsuo
 
ETL for Pros: Getting Data Into MongoDB
ETL for Pros: Getting Data Into MongoDBETL for Pros: Getting Data Into MongoDB
ETL for Pros: Getting Data Into MongoDBMongoDB
 
Powerful Analysis with the Aggregation Pipeline
Powerful Analysis with the Aggregation PipelinePowerful Analysis with the Aggregation Pipeline
Powerful Analysis with the Aggregation PipelineMongoDB
 
Grails: a quick tutorial (1)
Grails: a quick tutorial (1)Grails: a quick tutorial (1)
Grails: a quick tutorial (1)Davide Rossi
 
The Ring programming language version 1.5.4 book - Part 45 of 185
The Ring programming language version 1.5.4 book - Part 45 of 185The Ring programming language version 1.5.4 book - Part 45 of 185
The Ring programming language version 1.5.4 book - Part 45 of 185Mahmoud Samir Fayed
 
MongoDB Europe 2016 - Debugging MongoDB Performance
MongoDB Europe 2016 - Debugging MongoDB PerformanceMongoDB Europe 2016 - Debugging MongoDB Performance
MongoDB Europe 2016 - Debugging MongoDB PerformanceMongoDB
 
mobl presentation @ IHomer
mobl presentation @ IHomermobl presentation @ IHomer
mobl presentation @ IHomerzefhemel
 

What's hot (20)

MongoDB and Indexes - MUG Denver - 20160329
MongoDB and Indexes - MUG Denver - 20160329MongoDB and Indexes - MUG Denver - 20160329
MongoDB and Indexes - MUG Denver - 20160329
 
MongoDB - Aggregation Pipeline
MongoDB - Aggregation PipelineMongoDB - Aggregation Pipeline
MongoDB - Aggregation Pipeline
 
Groovy kind of test
Groovy kind of testGroovy kind of test
Groovy kind of test
 
Clean code
Clean codeClean code
Clean code
 
MongoDB crud
MongoDB crudMongoDB crud
MongoDB crud
 
Fast querying indexing for performance (4)
Fast querying   indexing for performance (4)Fast querying   indexing for performance (4)
Fast querying indexing for performance (4)
 
[제1회 루씬 한글분석기 기술세미나] solr로 나만의 검색엔진을 만들어보자
[제1회 루씬 한글분석기 기술세미나] solr로 나만의 검색엔진을 만들어보자[제1회 루씬 한글분석기 기술세미나] solr로 나만의 검색엔진을 만들어보자
[제1회 루씬 한글분석기 기술세미나] solr로 나만의 검색엔진을 만들어보자
 
MongoDB Days Silicon Valley: MongoDB and the Hadoop Connector
MongoDB Days Silicon Valley: MongoDB and the Hadoop ConnectorMongoDB Days Silicon Valley: MongoDB and the Hadoop Connector
MongoDB Days Silicon Valley: MongoDB and the Hadoop Connector
 
MongoDB Performance Tuning
MongoDB Performance TuningMongoDB Performance Tuning
MongoDB Performance Tuning
 
Query for json databases
Query for json databasesQuery for json databases
Query for json databases
 
Indexing and Query Optimizer (Mongo Austin)
Indexing and Query Optimizer (Mongo Austin)Indexing and Query Optimizer (Mongo Austin)
Indexing and Query Optimizer (Mongo Austin)
 
R and data mining
R and data miningR and data mining
R and data mining
 
20110514 mongo dbチューニング
20110514 mongo dbチューニング20110514 mongo dbチューニング
20110514 mongo dbチューニング
 
ETL for Pros: Getting Data Into MongoDB
ETL for Pros: Getting Data Into MongoDBETL for Pros: Getting Data Into MongoDB
ETL for Pros: Getting Data Into MongoDB
 
Powerful Analysis with the Aggregation Pipeline
Powerful Analysis with the Aggregation PipelinePowerful Analysis with the Aggregation Pipeline
Powerful Analysis with the Aggregation Pipeline
 
Grails: a quick tutorial (1)
Grails: a quick tutorial (1)Grails: a quick tutorial (1)
Grails: a quick tutorial (1)
 
The Ring programming language version 1.5.4 book - Part 45 of 185
The Ring programming language version 1.5.4 book - Part 45 of 185The Ring programming language version 1.5.4 book - Part 45 of 185
The Ring programming language version 1.5.4 book - Part 45 of 185
 
MongoDB Europe 2016 - Debugging MongoDB Performance
MongoDB Europe 2016 - Debugging MongoDB PerformanceMongoDB Europe 2016 - Debugging MongoDB Performance
MongoDB Europe 2016 - Debugging MongoDB Performance
 
mobl presentation @ IHomer
mobl presentation @ IHomermobl presentation @ IHomer
mobl presentation @ IHomer
 
Mongo db for C# Developers
Mongo db for C# DevelopersMongo db for C# Developers
Mongo db for C# Developers
 

Similar to Programação c#- Criar um documento no Word

Fcontratos
FcontratosFcontratos
Fcontratoskarlloss
 
The Ring programming language version 1.8 book - Part 50 of 202
The Ring programming language version 1.8 book - Part 50 of 202The Ring programming language version 1.8 book - Part 50 of 202
The Ring programming language version 1.8 book - Part 50 of 202Mahmoud Samir Fayed
 
The Ring programming language version 1.9 book - Part 53 of 210
The Ring programming language version 1.9 book - Part 53 of 210The Ring programming language version 1.9 book - Part 53 of 210
The Ring programming language version 1.9 book - Part 53 of 210Mahmoud Samir Fayed
 
Store and Process Big Data with Hadoop and Cassandra
Store and Process Big Data with Hadoop and CassandraStore and Process Big Data with Hadoop and Cassandra
Store and Process Big Data with Hadoop and CassandraDeependra Ariyadewa
 
The Ring programming language version 1.4.1 book - Part 13 of 31
The Ring programming language version 1.4.1 book - Part 13 of 31The Ring programming language version 1.4.1 book - Part 13 of 31
The Ring programming language version 1.4.1 book - Part 13 of 31Mahmoud Samir Fayed
 
NoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love StoryNoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love StoryAlexandre Morgaut
 
Adodb Scripts And Some Sample Scripts[1]
Adodb Scripts And Some Sample Scripts[1]Adodb Scripts And Some Sample Scripts[1]
Adodb Scripts And Some Sample Scripts[1]testduser1
 
Adodb Scripts And Some Sample Scripts[1]
Adodb Scripts And Some Sample Scripts[1]Adodb Scripts And Some Sample Scripts[1]
Adodb Scripts And Some Sample Scripts[1]User1test
 
Hadoop Integration in Cassandra
Hadoop Integration in CassandraHadoop Integration in Cassandra
Hadoop Integration in CassandraJairam Chandar
 
The Ring programming language version 1.5.2 book - Part 44 of 181
The Ring programming language version 1.5.2 book - Part 44 of 181The Ring programming language version 1.5.2 book - Part 44 of 181
The Ring programming language version 1.5.2 book - Part 44 of 181Mahmoud Samir Fayed
 
New text document
New text documentNew text document
New text documentTam Ngo
 
An introduction into Spring Data
An introduction into Spring DataAn introduction into Spring Data
An introduction into Spring DataOliver Gierke
 
Scalding - Hadoop Word Count in LESS than 70 lines of code
Scalding - Hadoop Word Count in LESS than 70 lines of codeScalding - Hadoop Word Count in LESS than 70 lines of code
Scalding - Hadoop Word Count in LESS than 70 lines of codeKonrad Malawski
 
Data access 2.0? Please welcome: Spring Data!
Data access 2.0? Please welcome: Spring Data!Data access 2.0? Please welcome: Spring Data!
Data access 2.0? Please welcome: Spring Data!Oliver Gierke
 
Introduction to Scalding and Monoids
Introduction to Scalding and MonoidsIntroduction to Scalding and Monoids
Introduction to Scalding and MonoidsHugo Gävert
 
Java development with MongoDB
Java development with MongoDBJava development with MongoDB
Java development with MongoDBJames Williams
 
Microsoft Ado
Microsoft AdoMicrosoft Ado
Microsoft Adooswchavez
 
Ss dotnetcodexmpl
Ss dotnetcodexmplSs dotnetcodexmpl
Ss dotnetcodexmplrpravi12
 
Erlang for data ops
Erlang for data opsErlang for data ops
Erlang for data opsmnacos
 

Similar to Programação c#- Criar um documento no Word (20)

Fcontratos
FcontratosFcontratos
Fcontratos
 
The Ring programming language version 1.8 book - Part 50 of 202
The Ring programming language version 1.8 book - Part 50 of 202The Ring programming language version 1.8 book - Part 50 of 202
The Ring programming language version 1.8 book - Part 50 of 202
 
The Ring programming language version 1.9 book - Part 53 of 210
The Ring programming language version 1.9 book - Part 53 of 210The Ring programming language version 1.9 book - Part 53 of 210
The Ring programming language version 1.9 book - Part 53 of 210
 
Store and Process Big Data with Hadoop and Cassandra
Store and Process Big Data with Hadoop and CassandraStore and Process Big Data with Hadoop and Cassandra
Store and Process Big Data with Hadoop and Cassandra
 
The Ring programming language version 1.4.1 book - Part 13 of 31
The Ring programming language version 1.4.1 book - Part 13 of 31The Ring programming language version 1.4.1 book - Part 13 of 31
The Ring programming language version 1.4.1 book - Part 13 of 31
 
NoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love StoryNoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love Story
 
Adodb Scripts And Some Sample Scripts[1]
Adodb Scripts And Some Sample Scripts[1]Adodb Scripts And Some Sample Scripts[1]
Adodb Scripts And Some Sample Scripts[1]
 
Adodb Scripts And Some Sample Scripts[1]
Adodb Scripts And Some Sample Scripts[1]Adodb Scripts And Some Sample Scripts[1]
Adodb Scripts And Some Sample Scripts[1]
 
Hadoop Integration in Cassandra
Hadoop Integration in CassandraHadoop Integration in Cassandra
Hadoop Integration in Cassandra
 
The Ring programming language version 1.5.2 book - Part 44 of 181
The Ring programming language version 1.5.2 book - Part 44 of 181The Ring programming language version 1.5.2 book - Part 44 of 181
The Ring programming language version 1.5.2 book - Part 44 of 181
 
New text document
New text documentNew text document
New text document
 
An introduction into Spring Data
An introduction into Spring DataAn introduction into Spring Data
An introduction into Spring Data
 
Scalding - Hadoop Word Count in LESS than 70 lines of code
Scalding - Hadoop Word Count in LESS than 70 lines of codeScalding - Hadoop Word Count in LESS than 70 lines of code
Scalding - Hadoop Word Count in LESS than 70 lines of code
 
Data access 2.0? Please welcome: Spring Data!
Data access 2.0? Please welcome: Spring Data!Data access 2.0? Please welcome: Spring Data!
Data access 2.0? Please welcome: Spring Data!
 
Code
CodeCode
Code
 
Introduction to Scalding and Monoids
Introduction to Scalding and MonoidsIntroduction to Scalding and Monoids
Introduction to Scalding and Monoids
 
Java development with MongoDB
Java development with MongoDBJava development with MongoDB
Java development with MongoDB
 
Microsoft Ado
Microsoft AdoMicrosoft Ado
Microsoft Ado
 
Ss dotnetcodexmpl
Ss dotnetcodexmplSs dotnetcodexmpl
Ss dotnetcodexmpl
 
Erlang for data ops
Erlang for data opsErlang for data ops
Erlang for data ops
 

Recently uploaded

Kurla Call Girls Pooja Nehwal📞 9892124323 ✅ Vashi Call Service Available Nea...
Kurla Call Girls Pooja Nehwal📞 9892124323 ✅  Vashi Call Service Available Nea...Kurla Call Girls Pooja Nehwal📞 9892124323 ✅  Vashi Call Service Available Nea...
Kurla Call Girls Pooja Nehwal📞 9892124323 ✅ Vashi Call Service Available Nea...Pooja Nehwal
 
SD_The MATATAG Curriculum Training Design.pptx
SD_The MATATAG Curriculum Training Design.pptxSD_The MATATAG Curriculum Training Design.pptx
SD_The MATATAG Curriculum Training Design.pptxjanettecruzeiro1
 
Raj Nagar Extension Call Girls 9711199012 WhatsApp No, Delhi Escorts in Raj N...
Raj Nagar Extension Call Girls 9711199012 WhatsApp No, Delhi Escorts in Raj N...Raj Nagar Extension Call Girls 9711199012 WhatsApp No, Delhi Escorts in Raj N...
Raj Nagar Extension Call Girls 9711199012 WhatsApp No, Delhi Escorts in Raj N...ankitnayak356677
 
Design Portfolio - 2024 - William Vickery
Design Portfolio - 2024 - William VickeryDesign Portfolio - 2024 - William Vickery
Design Portfolio - 2024 - William VickeryWilliamVickery6
 
Call Girls in Okhla Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Okhla Delhi 💯Call Us 🔝8264348440🔝Call Girls in Okhla Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Okhla Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
A level Digipak development Presentation
A level Digipak development PresentationA level Digipak development Presentation
A level Digipak development Presentationamedia6
 
3D Printing And Designing Final Report.pdf
3D Printing And Designing Final Report.pdf3D Printing And Designing Final Report.pdf
3D Printing And Designing Final Report.pdfSwaraliBorhade
 
Captivating Charm: Exploring Marseille's Hillside Villas with Our 3D Architec...
Captivating Charm: Exploring Marseille's Hillside Villas with Our 3D Architec...Captivating Charm: Exploring Marseille's Hillside Villas with Our 3D Architec...
Captivating Charm: Exploring Marseille's Hillside Villas with Our 3D Architec...Yantram Animation Studio Corporation
 
VIP Call Girls Service Kukatpally Hyderabad Call +91-8250192130
VIP Call Girls Service Kukatpally Hyderabad Call +91-8250192130VIP Call Girls Service Kukatpally Hyderabad Call +91-8250192130
VIP Call Girls Service Kukatpally Hyderabad Call +91-8250192130Suhani Kapoor
 
如何办理(UVa毕业证书)弗吉尼亚大学毕业证毕业证(文凭)成绩单原版一比一定制
如何办理(UVa毕业证书)弗吉尼亚大学毕业证毕业证(文凭)成绩单原版一比一定制如何办理(UVa毕业证书)弗吉尼亚大学毕业证毕业证(文凭)成绩单原版一比一定制
如何办理(UVa毕业证书)弗吉尼亚大学毕业证毕业证(文凭)成绩单原版一比一定制didi bibo
 
Revit Understanding Reference Planes and Reference lines in Revit for Family ...
Revit Understanding Reference Planes and Reference lines in Revit for Family ...Revit Understanding Reference Planes and Reference lines in Revit for Family ...
Revit Understanding Reference Planes and Reference lines in Revit for Family ...Narsimha murthy
 
ARt app | UX Case Study
ARt app | UX Case StudyARt app | UX Case Study
ARt app | UX Case StudySophia Viganò
 
How to Be Famous in your Field just visit our Site
How to Be Famous in your Field just visit our SiteHow to Be Famous in your Field just visit our Site
How to Be Famous in your Field just visit our Sitegalleryaagency
 
Call Us ✡️97111⇛47426⇛Call In girls Vasant Vihar༒(Delhi)
Call Us ✡️97111⇛47426⇛Call In girls Vasant Vihar༒(Delhi)Call Us ✡️97111⇛47426⇛Call In girls Vasant Vihar༒(Delhi)
Call Us ✡️97111⇛47426⇛Call In girls Vasant Vihar༒(Delhi)jennyeacort
 
shot list for my tv series two steps back
shot list for my tv series two steps backshot list for my tv series two steps back
shot list for my tv series two steps back17lcow074
 
CALL ON ➥8923113531 🔝Call Girls Aminabad Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Aminabad Lucknow best Night Fun serviceCALL ON ➥8923113531 🔝Call Girls Aminabad Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Aminabad Lucknow best Night Fun serviceanilsa9823
 
PORTAFOLIO 2024_ ANASTASIYA KUDINOVA
PORTAFOLIO   2024_  ANASTASIYA  KUDINOVAPORTAFOLIO   2024_  ANASTASIYA  KUDINOVA
PORTAFOLIO 2024_ ANASTASIYA KUDINOVAAnastasiya Kudinova
 
Cheap Rate Call girls Kalkaji 9205541914 shot 1500 night
Cheap Rate Call girls Kalkaji 9205541914 shot 1500 nightCheap Rate Call girls Kalkaji 9205541914 shot 1500 night
Cheap Rate Call girls Kalkaji 9205541914 shot 1500 nightDelhi Call girls
 

Recently uploaded (20)

Kurla Call Girls Pooja Nehwal📞 9892124323 ✅ Vashi Call Service Available Nea...
Kurla Call Girls Pooja Nehwal📞 9892124323 ✅  Vashi Call Service Available Nea...Kurla Call Girls Pooja Nehwal📞 9892124323 ✅  Vashi Call Service Available Nea...
Kurla Call Girls Pooja Nehwal📞 9892124323 ✅ Vashi Call Service Available Nea...
 
SD_The MATATAG Curriculum Training Design.pptx
SD_The MATATAG Curriculum Training Design.pptxSD_The MATATAG Curriculum Training Design.pptx
SD_The MATATAG Curriculum Training Design.pptx
 
Raj Nagar Extension Call Girls 9711199012 WhatsApp No, Delhi Escorts in Raj N...
Raj Nagar Extension Call Girls 9711199012 WhatsApp No, Delhi Escorts in Raj N...Raj Nagar Extension Call Girls 9711199012 WhatsApp No, Delhi Escorts in Raj N...
Raj Nagar Extension Call Girls 9711199012 WhatsApp No, Delhi Escorts in Raj N...
 
Design Portfolio - 2024 - William Vickery
Design Portfolio - 2024 - William VickeryDesign Portfolio - 2024 - William Vickery
Design Portfolio - 2024 - William Vickery
 
Call Girls in Okhla Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Okhla Delhi 💯Call Us 🔝8264348440🔝Call Girls in Okhla Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Okhla Delhi 💯Call Us 🔝8264348440🔝
 
A level Digipak development Presentation
A level Digipak development PresentationA level Digipak development Presentation
A level Digipak development Presentation
 
young call girls in Vivek Vihar🔝 9953056974 🔝 Delhi escort Service
young call girls in Vivek Vihar🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Vivek Vihar🔝 9953056974 🔝 Delhi escort Service
young call girls in Vivek Vihar🔝 9953056974 🔝 Delhi escort Service
 
3D Printing And Designing Final Report.pdf
3D Printing And Designing Final Report.pdf3D Printing And Designing Final Report.pdf
3D Printing And Designing Final Report.pdf
 
Captivating Charm: Exploring Marseille's Hillside Villas with Our 3D Architec...
Captivating Charm: Exploring Marseille's Hillside Villas with Our 3D Architec...Captivating Charm: Exploring Marseille's Hillside Villas with Our 3D Architec...
Captivating Charm: Exploring Marseille's Hillside Villas with Our 3D Architec...
 
VIP Call Girls Service Kukatpally Hyderabad Call +91-8250192130
VIP Call Girls Service Kukatpally Hyderabad Call +91-8250192130VIP Call Girls Service Kukatpally Hyderabad Call +91-8250192130
VIP Call Girls Service Kukatpally Hyderabad Call +91-8250192130
 
如何办理(UVa毕业证书)弗吉尼亚大学毕业证毕业证(文凭)成绩单原版一比一定制
如何办理(UVa毕业证书)弗吉尼亚大学毕业证毕业证(文凭)成绩单原版一比一定制如何办理(UVa毕业证书)弗吉尼亚大学毕业证毕业证(文凭)成绩单原版一比一定制
如何办理(UVa毕业证书)弗吉尼亚大学毕业证毕业证(文凭)成绩单原版一比一定制
 
Revit Understanding Reference Planes and Reference lines in Revit for Family ...
Revit Understanding Reference Planes and Reference lines in Revit for Family ...Revit Understanding Reference Planes and Reference lines in Revit for Family ...
Revit Understanding Reference Planes and Reference lines in Revit for Family ...
 
Call Girls Service Mukherjee Nagar @9999965857 Delhi 🫦 No Advance VVIP 🍎 SER...
Call Girls Service Mukherjee Nagar @9999965857 Delhi 🫦 No Advance  VVIP 🍎 SER...Call Girls Service Mukherjee Nagar @9999965857 Delhi 🫦 No Advance  VVIP 🍎 SER...
Call Girls Service Mukherjee Nagar @9999965857 Delhi 🫦 No Advance VVIP 🍎 SER...
 
ARt app | UX Case Study
ARt app | UX Case StudyARt app | UX Case Study
ARt app | UX Case Study
 
How to Be Famous in your Field just visit our Site
How to Be Famous in your Field just visit our SiteHow to Be Famous in your Field just visit our Site
How to Be Famous in your Field just visit our Site
 
Call Us ✡️97111⇛47426⇛Call In girls Vasant Vihar༒(Delhi)
Call Us ✡️97111⇛47426⇛Call In girls Vasant Vihar༒(Delhi)Call Us ✡️97111⇛47426⇛Call In girls Vasant Vihar༒(Delhi)
Call Us ✡️97111⇛47426⇛Call In girls Vasant Vihar༒(Delhi)
 
shot list for my tv series two steps back
shot list for my tv series two steps backshot list for my tv series two steps back
shot list for my tv series two steps back
 
CALL ON ➥8923113531 🔝Call Girls Aminabad Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Aminabad Lucknow best Night Fun serviceCALL ON ➥8923113531 🔝Call Girls Aminabad Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Aminabad Lucknow best Night Fun service
 
PORTAFOLIO 2024_ ANASTASIYA KUDINOVA
PORTAFOLIO   2024_  ANASTASIYA  KUDINOVAPORTAFOLIO   2024_  ANASTASIYA  KUDINOVA
PORTAFOLIO 2024_ ANASTASIYA KUDINOVA
 
Cheap Rate Call girls Kalkaji 9205541914 shot 1500 night
Cheap Rate Call girls Kalkaji 9205541914 shot 1500 nightCheap Rate Call girls Kalkaji 9205541914 shot 1500 night
Cheap Rate Call girls Kalkaji 9205541914 shot 1500 night
 

Programação c#- Criar um documento no Word

  • 1. private void CriarDocWord() { object oRng; object oMissing = System.Reflection.Missing.Value; object oEndOfDoc = "endofdoc"; /* endofdoc is a predefined bookmark */ Word._Application WORD; Word._Document oDoc; WORD = new Word.Application(); WORD.Visible = false; oDoc = WORD.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing); //Insert a paragraph at the beginning of the document. Word.Paragraph Nome; Nome = oDoc.Content.Paragraphs.Add(ref oMissing); Nome.Range.Font.Bold = 1; Nome.Format.SpaceBefore = 10; Nome.Format.SpaceAfter = 24; //24 pt spacing after paragraph. Nome.Range.InsertParagraphAfter(); //banco-------------------------------------------- OdbcConnection conexao = new OdbcConnection(strConex); conexao.Open(); OdbcCommand cSQL = new OdbcCommand("select nm_prato from prato where cd_prato =" + cboCodigo.Text, conexao); OdbcDataReader dados = cSQL.ExecuteReader(); string nomeprato = ""; if (dados.HasRows) while (dados.Read()) { Nome.Range.Text = "PRATO: " + dados[0].ToString(); Nome.Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft; nomeprato = dados[0].ToString(); } dados.Close(); conexao.Close(); dados.Dispose(); conexao.Dispose(); Word.Paragraph TEMPO; oRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range; TEMPO = oDoc.Content.Paragraphs.Add(ref oRng); TEMPO.Range.Font.Bold = 1; TEMPO.Format.SpaceAfter = 6; TEMPO.Range.InsertParagraphAfter(); conexao = new OdbcConnection(strConex); conexao.Open(); cSQL = new OdbcCommand("select hr_preparo from prato where cd_prato =" + cboCodigo.Text, conexao); dados = cSQL.ExecuteReader(); if (dados.HasRows) while (dados.Read()) TEMPO.Range.Text = "TEMPO DE PREPARO: " + dados[0].ToString() + " Minutos"; TEMPO.Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft; dados.Close(); conexao.Close(); dados.Dispose(); conexao.Dispose();
  • 2. Word.Paragraph RENDIMENTO; oRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range; RENDIMENTO = oDoc.Content.Paragraphs.Add(ref oRng); RENDIMENTO.Range.Font.Bold = 1; RENDIMENTO.Format.SpaceAfter = 6; RENDIMENTO.Range.InsertParagraphAfter(); conexao = new OdbcConnection(strConex); conexao.Open(); cSQL = new OdbcCommand("select qt_serve from prato where cd_prato =" + cboCodigo.Text, conexao); dados = cSQL.ExecuteReader(); if (dados.HasRows) while (dados.Read()) RENDIMENTO.Range.Text = "RENDIMENTO : " + dados[0].ToString() + " Pessoas"; RENDIMENTO.Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft; dados.Close(); conexao.Close(); dados.Dispose(); conexao.Dispose(); Word.Paragraph UTENSILIOS; oRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range; UTENSILIOS = oDoc.Content.Paragraphs.Add(ref oRng); UTENSILIOS.Range.Font.Bold = 1; UTENSILIOS.Format.SpaceAfter = 6; UTENSILIOS.Range.InsertParagraphAfter(); conexao = new OdbcConnection(strConex); conexao.Open(); cSQL = new OdbcCommand("select ds_utensilio from prato where cd_prato =" + cboCodigo.Text, conexao); dados = cSQL.ExecuteReader(); if (dados.HasRows) while (dados.Read()) UTENSILIOS.Range.Text = " UTENSÍLIOS E EQUIPAMENTOS : " + dados[0].ToString() + " Pessoas"; UTENSILIOS.Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft; dados.Close(); conexao.Close(); dados.Dispose(); conexao.Dispose(); Word.Table oTable; Word.Range wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range; oTable = oDoc.Tables.Add(wrdRng, listBox1.Items.Count + 4, 5, ref oMissing, ref oMissing); oTable.Range.ParagraphFormat.SpaceAfter = 6; oTable.Cell(1, 1).Range.Text = "PRODUTO"; oTable.Cell(1, 2).Range.Text = "PESO BRUTO"; oTable.Cell(1, 3).Range.Text = "PESO LÍQUIDO"; oTable.Cell(1, 4).Range.Text = "IPC"; oTable.Cell(1, 5).Range.Text = "VALOR UNITÁRIO"; listBox1.Items.Clear(); listBox2.Items.Clear(); listBox3.Items.Clear(); listBox4.Items.Clear(); listBox5.Items.Clear();
  • 3. string c = ""; x = 2; comando = "SELECT m.nm_materia_prima INGREDIENTE,i.qt_materia_prima QTDE,truncate( ((i.qt_materia_prima)-( ( ((m.qt_ipc_materia_prima -1) *100) * i.qt_materia_prima ) /100)),3), m.qt_ipc_materia_prima,m.vl_unitario_materia_prima AS 'VALOR UNITARIO'"; comando += " from materia_prima m join ingrediente_receita i"; comando += " on (i.cd_materia_prima=m.cd_materia_prima)"; comando += " join unidade_medida u on (u.cd_unidade_medida=i.cd_unidade_medida)"; comando += " where i.cd_prato=" + cboCodigo.Text; Insere(comando); double total = 0; int _i; for (int i = 2; i <= listBox1.Items.Count + 1; i++) { _i = i - 2; string aa = listBox1.Items[_i].ToString(), bb = listBox2.Items[_i].ToString(), cc = listBox3.Items[_i].ToString(), dd = listBox4.Items[_i].ToString(), ee = listBox5.Items[_i].ToString(); aa = aa.Replace(",", "."); bb = bb.Replace(",", "."); cc = cc.Replace(",", "."); dd = dd.Replace(",", "."); ee = ee.Replace(",", "."); oTable.Cell(i, 1).Range.Text = aa; oTable.Cell(i, 2).Range.Text = bb; oTable.Cell(i, 3).Range.Text = cc; oTable.Cell(i, 4).Range.Text = dd; oTable.Cell(i, 5).Range.Text = ee; } oTable.Rows[1].Range.Font.Bold = 1; oTable.Rows[1].Range.Font.Italic = 1; WORD.Selection.TypeParagraph(); Word.Paragraph modo_preparo; oRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range; modo_preparo = oDoc.Content.Paragraphs.Add(ref oRng); modo_preparo.Format.SpaceAfter = 10; modo_preparo.Range.Font.Bold = 1; modo_preparo.Range.InsertParagraphAfter(); conexao = new OdbcConnection(strConex); conexao.Open(); cSQL = new OdbcCommand("select ds_modo_preparo from prato where cd_prato =" + cboCodigo.Text, conexao); dados = cSQL.ExecuteReader(); if (dados.HasRows) while (dados.Read()) modo_preparo.Range.Text = "MODO DE PREPARO: " + dados[0].ToString(); dados.Close(); conexao.Close(); dados.Dispose(); conexao.Dispose(); Word.Paragraph valor_prato; oRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range; valor_prato = oDoc.Content.Paragraphs.Add(ref oRng); valor_prato.Format.SpaceAfter = 20; valor_prato.Range.Font.Bold = 1; valor_prato.Range.InsertParagraphAfter(); conexao = new OdbcConnection(strConex);
  • 4. conexao.Open(); cSQL = new OdbcCommand("select vl_prato from prato where cd_prato =" + cboCodigo.Text, conexao); dados = cSQL.ExecuteReader(); if (dados.HasRows) while (dados.Read()) valor_prato.Range.Text = "VALOR : " + dados[0].ToString(); valor_prato.Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight; dados.Close(); conexao.Close(); dados.Dispose(); conexao.Dispose(); Word.Paragraph valor_sugerido; oRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range; valor_sugerido = oDoc.Content.Paragraphs.Add(ref oRng); valor_sugerido.Format.SpaceAfter = 20; valor_sugerido.Range.Font.Bold = 1; valor_sugerido.Range.InsertParagraphAfter(); conexao = new OdbcConnection(strConex); conexao.Open(); string conta = "SELECT truncate( sum((i.qt_materia_prima * m.vl_unitario_materia_prima)/1000),2) from materia_prima m join ingrediente_receita i "; conta += "on (m.cd_materia_prima = i.cd_materia_prima) where i.cd_prato =" + cboCodigo.Text; cSQL = new OdbcCommand(conta,conexao); dados = cSQL.ExecuteReader(); if (dados.HasRows) while (dados.Read()) valor_sugerido.Range.Text = "PREÇO SUGERIDO : " + dados[0].ToString(); valor_sugerido.Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight; dados.Close(); conexao.Close(); dados.Dispose(); conexao.Dispose(); try { conexao = new OdbcConnection(strConex); conexao.Open(); cSQL = new OdbcCommand("select nm_imagem_prato from prato where cd_prato =" + cboCodigo.Text, conexao); dados = cSQL.ExecuteReader(); if (dados.HasRows) while (dados.Read()) oRng = oDoc.Application.Selection.InlineShapes.AddPicture(dados[0].ToString()).ScaleHei ght = 30; oRng = oDoc.Application.Selection.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter; dados.Close(); conexao.Close(); dados.Dispose(); conexao.Dispose(); } catch { } WORD.Selection.TypeParagraph();
  • 5. WORD.Selection.TypeParagraph(); //SALVAR oDoc.SaveAs(Application.StartupPath.Substring(0, Application.StartupPath.Length - 10) + "Documentos Temporarios"+nomeprato+".docx" ); oDoc.Close(ref oMissing, ref oMissing, ref oMissing); WORD.Quit(ref oMissing, ref oMissing, ref oMissing); oDoc = null; WORD = null; // Converte para PDF // Create a new Microsoft Word application object Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application(); // C# doesn't have optional arguments so we'll need a dummy value object oMissing1 = System.Reflection.Missing.Value; // Get list of Word files in specified directory DirectoryInfo dirInfo = new DirectoryInfo(Application.StartupPath.Substring(0, Application.StartupPath.Length - 10) + "Documentos Temporarios"); FileInfo[] wordFiles = dirInfo.GetFiles("*.docx"); word.Visible = false; word.ScreenUpdating = false; foreach (FileInfo wordFile in wordFiles) { // Cast as Object for word Open method Object filename = (Object)wordFile.FullName; // Use the dummy value as a placeholder for optional arguments Word.Document doc = word.Documents.Open(ref filename, ref oMissing1, ref oMissing1, ref oMissing1, ref oMissing1, ref oMissing1, ref oMissing1, ref oMissing1, ref oMissing1, ref oMissing1, ref oMissing1, ref oMissing1, ref oMissing1, ref oMissing1, ref oMissing1, ref oMissing1); doc.Activate(); object outputFileName = wordFile.FullName.Replace(".docx", ".pdf"); object fileFormat = Word.WdSaveFormat.wdFormatPDF; // Save document into PDF Format doc.SaveAs(ref outputFileName, ref fileFormat, ref oMissing1, ref oMissing1, ref oMissing1, ref oMissing1, ref oMissing1, ref oMissing1, ref oMissing1, ref oMissing1, ref oMissing1, ref oMissing1, ref oMissing1, ref oMissing1, ref oMissing1, ref oMissing1); // Close the Word document, but leave the Word application open. // doc has to be cast to type _Document so that it will find the // correct Close method. object saveChanges = Word.WdSaveOptions.wdDoNotSaveChanges; ((Word.Document)doc).Close(ref saveChanges, ref oMissing1, ref oMissing1); doc = null; } // word has to be cast to type _Application so that it will find // the correct Quit method.
  • 6. ((Word.Application)word).Quit(ref oMissing1, ref oMissing1, ref oMissing1); word = null; System.Diagnostics.Process.Start(Application.StartupPath.Substring(0, Application.StartupPath.Length - 10) + "Documentos Temporarios" + nomeprato + ".pdf");