C# NPOI-将excel文件的一部分嵌入电子邮件C中#
我想使用SMTP发送包含嵌入excel数据的电子邮件 我使用datatable获取外部数据,并使用datatable的一部分创建excel文件。我只想嵌入excel文件的4行。如何将sheet1更改为html以嵌入电子邮件C# NPOI-将excel文件的一部分嵌入电子邮件C中#,c#,excel,smtp,npoi,C#,Excel,Smtp,Npoi,我想使用SMTP发送包含嵌入excel数据的电子邮件 我使用datatable获取外部数据,并使用datatable的一部分创建excel文件。我只想嵌入excel文件的4行。如何将sheet1更改为html以嵌入电子邮件 private void Email() { //get the data from database DataTable data = GetData(); IWorkbook workbook;
private void Email()
{
//get the data from database
DataTable data = GetData();
IWorkbook workbook;
workbook = new HSSFWorkbook();
ISheet sheet1 = workbook.CreateSheet("Sheet 1");
....
}
你的问题不是很具体,但我想我理解
int startingRow = 0; // Row 1 in Excel is Row 0 in NPOI
int endingRow = 4;
StringBuilder builder = new StringBuilder();
builder.Append("<table>");
for (int r = startingRow; r < endingRow; r++)
{
// Check if current row is null
if (sheet1.GetRow(r) != null)
{
builder.Append("<tr>");
// Get the current row
IRow row = sheet1.GetRow(r);
// Loop through each cell in the row
for (int c = 0; c < row.LastCellNum; c++)
{
builder.Append("<td>");
// Check if current cell is null
if (row.GetCell(c) != null)
{
// Get cell value
ICell cell = row.GetCell(c);
// Append cell value between HTML table cells
builder.Append(cell.ToString());
}
builder.Append("</td>");
}
builder.Append("</tr>");
}
}
builder.Append("</table>");
// insert builder.ToString(); in your e-mail
int startingRow=0;//Excel中的第1行是NPOI中的第0行
int endingRow=4;
StringBuilder=新的StringBuilder();
生成器。追加(“”);
对于(int r=startingRow;r
哦,是的,这正是我想要做的。。。row.GetCell()是获取数据的方法。。非常感谢。