0

C# を使用して Excel VSTO プロジェクトに取り組んでいます。Excel は、"SEP-1" のようなコードを日付に自動フォーマットしますが、これは想定された動作ではありません。コード内のスプレッドシートでこの機能をオフにする方法はありますか? ありがとう!

4

2 に答える 2

0

テキスト値の前に一重引用符を付けることができます。

次のコード スニペットは、C# でどのように実行できるかを確認するための擬似コードとして提供されています。

Excel.Range vsto_cell = vsto_worksheet.Cells[row_index + 1, col_index + 1];

if( ( ssg_cell.NumberFormatType == SpreadsheetGear.NumberFormatType.Date )
   || ( ssg_cell.NumberFormatType == SpreadsheetGear.NumberFormatType.DateTime )
   || ( ssg_cell.NumberFormatType == SpreadsheetGear.NumberFormatType.Time ) )
{
   vsto_cell.Value2 = ssg_cell.Text; //date should be recognized by Excel as a date
}
else if( ssg_cell.ValueType == SpreadsheetGear.ValueType.Text )
{
   vsto_cell.Value2 = "'" + ssg_cell.Text;
}
else
   vsto_cell.Value2 = ssg_cell.Value;
于 2013-09-25T10:05:08.417 に答える