private void button1_Click(object sender, EventArgs e) { try { string directorio = Application.StartupPath + "\\WordDocs\\"; string outputPath = @directorio + "\\ArchivoUnificado.doc"; string template = directorio + "\\Template.dot"; string temp1 = directorio + "\\Temp1.doc"; if (File.Exists(outputPath)) { File.Delete(outputPath); } if (!File.Exists(temp1)) { File.Create(temp1).Close(); } MySqlConnection conn = new MySqlConnection(builder.ToString()); conn.Open(); MySqlDataReader rdr; using (var cmd = new MySqlCommand("SELECT contrato FROM perlab Limit 1,7", conn)) { rdr = cmd.ExecuteReader(); while (rdr.Read()) { if (rdr[0] != DBNull.Value) { Byte[] data = (Byte[])rdr[0]; FileStream fs = File.Open(temp1, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite); fs.Write(data, 0, data.Length); fs.Close(); if (!File.Exists(outputPath)) { File.Copy(temp1, outputPath); } else { WordMerge.Merge(new string[] { temp1, outputPath }, outputPath, true, template); } Console.Write("ad"); } } } conn.Close(); File.Delete(temp1); MessageBox.Show("Listo"); } catch (Exception ex) { MessageBox.Show("Error: " + ex); } }
private void Button_Click_3(object sender, RoutedEventArgs e) { Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog(); // Set filter for file extension and default file extension dlg.DefaultExt = ".docx"; dlg.Filter = "Word Files (*.docx)|*.docx|PNG Files (*.png)|*.png|JPG Files (*.jpg)|*.jpg|GIF Files (*.gif)|*.gif"; //Display OpenFileDialog by calling ShowDialog method Nullable <bool> result = dlg.ShowDialog(); //Get the selected file name and display in a TextBox if (result == true) { // Open document string filename = dlg.FileName; ILocalMerge merge = new WordMerge(); merge.Run(filename); } //Service.Service1SoapClient serviceClient = new Service.Service1SoapClient(); //var resultFile = serviceClient.MergeDocument(result); //int dupa = 1; }
public byte[] MergeWord(PersonFiles[] files) { IMerge merge = new WordMerge(); return(merge.Run(new List <PersonFiles>(files))); }