//instantiate wordDoc and wordApp
string PathDoc, DateTemp = string.Empty;
DateTime dDateTemp = new DateTime();
dDateTemp = Convert.ToDateTime(sDate);
var ds = new DataSet();
string textDate = dDateTemp.ToString("MM/dd/yy");
switch (msDateType)
{
case "D":
sSQL = string.Format(msQuery+"'{0}'",textDate);
break;
case "W":
dDateTemp = dDateTemp.AddDays(4);
DateTemp = dDateTemp.Month.ToString("MM") + "/" + dDateTemp.Day.ToString("dd")
+ "/" + dDateTemp.Year.ToString("yy");
sSQL = msQuery + " @textDate";
//sSQL = msQuery + " '" + textDate + "' AND '" + DateTemp + "'";
MessageBox.Show(sSQL);
break;
case "N":
sSQL = msQuery;
break;
default:
break;
}
string test = "SELECT * FROM ltrFammedNoShow WHERE ApptDt = '06/01/2015'";
int same = string.Compare(test, sSQL, true);
using (cn = new SqlConnection(connectionString))
{
cn.Open();
using (SqlCommand command = cn.CreateCommand())
{
command.CommandText = test;
// "select top 10 * from ltrFammedNoShow"; //
//command.Parameters.Add(@textDate, SqlDbType.NVarChar,15);
//command.Parameters[@textDate].Value = textDate;
//MessageBox.Show(command.CommandText);
var adapter = new SqlDataAdapter(command);
adapter.Fill(ds);
}
}
//Set the path and document of the letter to be used for the merge
PathDoc = msPath + "\"" + msDocument;
//Create a new instance of the word Application
wordApp = new Microsoft.Office.Interop.Word.Application();
//Add a new document
wordDoc = wordApp.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);
wordDoc.Select();
//Create MailMerge data document
CreateDataDoc(ref wordApp, ref ds);
wordDoc = wordApp.Documents.Add(Template: @"D:\ClinicLetters\Fammed\NoShow.doc");
wordApp.Visible = true;
wordDoc.MailMerge.OpenDataSource(@"D:\\data.doc");
//wordDoc.MailMerge.Destination = WdMailMergeDestination.wdSendToNewDocument;
//wordDoc.MailMerge.Execute(ref oFalse);
wordDoc.MailMerge.Execute(ds);
//wordDoc.Words.Last.InsertBreak(Microsoft.Office.Interop.Word.WdBreakType.wdPageBreak);
//Close the original form document
wordDoc.Saved = false;
wordDoc.Close(ref oFalse, ref oMissing, ref oMissing);
//Release reference
wordDoc = null;
wordApp = null;
J'ai essayé tout ce que je pouvais penser à plusieurs lettres de produit (qui restent dans le même document pour faciliter l'impression) mais j'ai continué à obtenir une erreur de type incompatibilité. Quelqu'un peut-il aider? Toutes les opinions sont très appréciées. Merci d'avance.Exécute l'opération de fusion et publipostage de nombreux documents. Type Erreur d'incompatibilité
Sur quelle ligne l'erreur se produit-elle? –
Pour effectuer une opération de fusion et publipostage, une solution alternative à Microsoft.Office.Interop consiste à créer un document Word réel en fusionnant le courrier standard et en l'associant à un fichier CSV. Dans C#, vous devez créer le fichier csv avec tous les champs variables (une ligne pour chaque lettre) et exécuter Word (en utilisant Process.start) pour afficher ou imprimer les lettres. – Graffito
@ 3-14159265358979323846264 wordDoc.MailMerge.Execute (ds); – user3808539