Ошибка в цикле "for", не удается отправить почту через outlook
Я выполнил свою работу, но Почта не отправляется. Фактически компилятор не может достичь цикла "for". Я должен извлечь строки (A-H), где присутствует символ "d". Предположим, если "d "присутствует в столбце" M "в ячейке" M6", то мне нужно извлечь A6-H6 и отправить его по почте outlook.
Пожалуйста, помогите мне!
Это то, что я сделал до сих пор :
Что я уже пробовал:
using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Text; using Excel = Microsoft.Office.Interop.Excel; using Outlook = Microsoft.Office.Interop.Outlook; using System.Collections; namespace XYZ { class Program { //method to send email to outlook public static void sendEMailThroughOUTLOOK() { try { // Create the Outlook application. Outlook.Application oApp = new Outlook.Application(); // Create a new mail item. Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem); // Set HTMLBody. //add the body of the email oMsg.HTMLBody = "See the details"; //Subject line oMsg.Subject = "Doc Info"; // Add a recipient. Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients; // Change the recipient in the next line if necessary. Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add("abc@xyz.com"), oRecip.Resolve(); // Send. oMsg.Send(); // Clean up. oRecip = null; oRecips = null; oMsg = null; oApp = null; } catch (Exception ex) { } } private static string EX_PATH = @"F:\Document_Excel.xlsm"; private static Excel.Workbook AXBook = null; private static Excel.Application AXApp = null; private static Excel.Worksheet AXSheet = null; public static string exception = ""; static void Main(string[] args) { if (args == null || args.Length < 4) { Console.WriteLine("Let's start the work!"); Console.WriteLine("press any key to continue"); Console.ReadLine(); } else { AX_PATH = args[0]; } AXApp = new Excel.Application(); AXApp.Visible = true; exception = ""; try { AXBook = AXApp.Workbooks.Open(AX_PATH, 0, true, 5, "", "", true,Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0); } catch (System.Exception ex) { exception = ex.Message; } exception = ""; try { AXSheet = (Excel.Worksheet)AXBook.Sheets["Sheet First"]; } catch (Exception ex) { exception = ex.Message; } Console.WriteLine("Hello"); Excel.Range last = AXSheet.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell, Type.Missing); Excel.Range range = AXSheet.get_Range("A1", last); int lastUsedRow = last.Row; int lastUsedColumn = last.Column; Object missing = System.Type.Missing; for (int i = AXSheet.Cells.get_Range("d", missing).Row + 1; i <= last.Row; i++) { Console.WriteLine("Hello"); sendEMailThroughOUTLOOK(); } } } }