在 codeproject 上看看这个。如评论中所述,如果您使用的是 Interop,则不需要连接字符串。您可以简单地打开一个工作簿,获取项目数组(对象数组),然后对每个项目调用 ToString() 以获取其字符串表示形式。这样的事情应该做:
ApplicationClass app = new ApplicationClass();
app.Visible = false;
app.ScreenUpdating = false;
app.DisplayAlerts = false;
Workbook book = app.Workbooks.Open(@"path\Book1.xls",
Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value);
Worksheet sheet = (Worksheet)book.Worksheets[1];
Range range = sheet.get_Range(...);
string execPath = Path.GetDirectoryName(
Assembly.GetExecutingAssembly().CodeBase);
object[,] values = (object[,])range.Value2;
for (int i = 1; i <= values.GetLength(0); i++)
{
for (int j = 1; j <= values.GetLength(1); j++)
{
string s = values[i, j].ToString();
}
}