locked
Howto pass Sheetname in OpendataSource Mail merge Excel c# RRS feed

  • Question

  • Hello,

     

    I am DOing Mailmerge using Excel file as datasource .I want to pass Sheet name in opendatasource method .

               

                 string reg="SOFTWARE\\mysample\\v1.0";
              string excelfile="c\\Sample.xlsx";
                 object Connection = "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Engine type=35;Data Source=" + excelfile + ";Extended Properties=\"HDR=YES;IMEX=1;\";Jet OLE DB:Registry Path=" + reg + "";
                object SQLStatement = "SELECT * FROM [Sheet1$]";
                object SubType = Microsoft.Office.Interop.Word.WdMergeSubType.wdMergeSubTypeWord;
             
                object objMiss = Type.Missing;
                object objFalse = false;
                object objTrue = true;
                object format = Microsoft.Office.Interop.Word.WdOpenFormat.wdOpenFormatText;
                object readOnly = true;

               docWord.MailMerge.OpenDataSource(" + excelfile + ", ref format, ref objFalse,
                  ref readOnly, ref objTrue,
                  ref objFalse, ref objMiss, ref objMiss, ref objMiss, ref
                     objMiss, ref objMiss, ref objMiss,
                  ref SQLStatement, ref objMiss, ref objMiss, ref SubType);

     
    But it does not takes call sheet1 .

    Howto pass sheet1?

    Shubha

     

     


    shobha
    Monday, May 17, 2010 1:53 PM