它是如何与 excel 一起工作的
decimal LTLPrice = Decimal.Parse(sheet.get_Range("H27").Value.ToString());
decimal mathLTLPrice = Math.Round(LTLPrice, 2);
sheet.get_Range("C29").Value = SumToTextFormatProvider.SumToText(mathLTLPrice, "Lt", "ct");
OleDb 在我的想象中应该是怎样的
myCommand = new OleDbCommand("SELECT * FROM [Sheet1$H27:H27]", MyConnection);
myReader = myCommand.ExecuteReader();
while (myReader.Read())
{
decimal LTLPrice = Decimal.Parse(myReader.GetString(0));
decimal mathLTLPrice = Math.Round(LTLPrice, 2);
myCommand = new OleDbCommand("UPDATE [Sheet1$C29:C29] SET F1='" + SumToTextFormatProvider.SumToText(mathLTLPrice, "Lt", "ct") + "'", MyConnection);
myCommand.ExecuteNonQuery();
}
myReader.Close();
怎么样
System.InvalidCastException: Specified cast is not valid.
at System.Data.OleDb.ColumnBinding.ValueString()
at System.Data.OleDb.OleDbDataReader.GetString(Int32 ordinal)
at Trains.invoiceForm.invoiceGenerateXls_Click(Object sender, EventArgs e) in D:\Users\Nullified\Documents\Visual Studio 2010\Projects\Trains\Trains\invoiceForm.cs:line 592
错误在这一行
decimal LTLPrice = Decimal.Parse(myReader.GetString(0));
我试过 GetInt32 / GetDecimal 但没有结果。:(
更新
使用 GetDouble 我没有收到错误,但 myReader 返回 0,然后在 excel 中它是“3,49”