我必须在现有的Excel文件中插入注释,
使用OleDb
连接。
这是我的Insert方法,如何将Excel注释添加到特定单元格?
private static string BuildInsertCommand(DataTable dataTable, int rowIndex)
{
StringBuilder sb = new StringBuilder();
sb.AppendFormat("INSERT INTO [{0}$](", BuildExcelSheetName(dataTable));
for (int i = 0; i < dataTable.Columns.Count; i++)
sb.Append("F"+(i+1)+",");
sb = sb.Replace(',', ')', sb.ToString().LastIndexOf(','), 1);
sb.Append("VALUES (");
foreach (DataColumn col in dataTable.Columns)
{
string type = col.DataType.ToString();
string strToInsert = String.Empty;
strToInsert = dataTable.Rows[rowIndex][col].ToString().Replace("'", "''");
sb.AppendFormat("'{0}',", strToInsert);
}
sb = sb.Replace(',', ')', sb.ToString().LastIndexOf(','), 1);
return sb.ToString();
}