“for循环”中的错误 [英] Error in "for loop"

查看:93
本文介绍了“for循环”中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经实现了我的工作,但邮件没有被发送。实际上,编译器无法到达"for"。环。我必须提取字符"d"的行(A-H)。
存在。假设"d"是否为"d"。在"M"列中存在"M"。在"M6"处单元格,然后我需要提取A6-H6并通过Outlook邮件发送。




< span style ="color:#222222; font-family:Verdana,sans-serif; font-size:14px">请帮助我!



这是我到目前为止所做的:



使用Sys tem; 

使用System.IO; 

using System.Collections.Generic; 

使用System.Linq; 

使用System.Text; 

使用Excel = Microsoft.Office.Interop.Excel; 

使用Outlook = Microsoft.Office.Interop.Outlook;



使用System.Collections;



命名空间XYZ 



class Program 



//向outlook发送电子邮件的方法 

public static void sendEMailThroughOUTLOOK() 



尝试 



//创建Outlook应用程序。 

Outlook.Application oApp = new Outlook.Application();



//创建一个新的邮件项目。 

Outlook.MailItem oMsg = 

(Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);



//设置HTMLBody。 

//添加电子邮件正文 

oMsg.HTMLBody ="查看详细信息" ;;



//主题行oMsg.Subject =" Doc Info";



//添加收件人。 

Outlook.Recipients oRecips =(Outlook.Recipients)oMsg.Recipients;



//如有必要,在下一行更改收件人。 

Outlook.Recipient oRecip =(Outlook.Recipient)oRecips.Add(" abc@xyz.com"),oRecip.Resolve();



//发送。 

oMsg.Send();



//清理。 

oRecip = null; 

oRecips = null; 

oMsg = null; 

oApp = null; 



catch(Exception ex) 





}



私有静态字符串EX_PATH = @" F:\Document_Excel.xlsm"; 

私有静态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("让我们开始工作!"); 

Console.WriteLine("按任意键继续"); 

Console.ReadLine(); 



else 



AX_PATH = args [0]; 

}



AXApp = new Excel.Application(); 

AXApp.Visible = true;



exception ="" ;; 

尝试 



AXBook = AXApp.Workbooks.Open(AX_PATH,0,true,则如图5所示,"","" ;,真,Microsoft.Office.Interop.Excel.XlPlatform.xlWindows," \\ \\ t",false,false,0,true,1,0;) 



catch(System.Exception ex) 



exception = ex.Message; 

}



exception ="" ;; 

尝试 



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;



对象缺失= System.Type.Missing; 

for(int i = AXSheet.Cells.get_Range(" d",missing).Row + 1; i< = last.Row; i ++) 

{



Console.WriteLine(" Hello"); 

sendEMailThroughOUTLOOK(); 

}





}



I have implemented my work, but the mail is not getting sent. Infact, the compiler can't reach the "for" loop. I have to extract the rows(A-H) where character "d" is present. Suppose if "d" is present in column "M" at "M6" cell, then I need to extract A6-H6 and send it via outlook mail.

Please help me!

This is what I have done so far :

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(); 
}


}

推荐答案

最好的办法是在有问题的代码之前设置一个断点,逐步执行代码并检查变量数据以查看值是什么,并确定如何继续。
Best thing to do is set a break point prior to the problematic code, step through the code and examine variable data to see what the values are and determine how to proceed.


这篇关于“for循环”中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆