/// <summary> /// DataGridViewのセルオブジェクトから、Excelの表示形式を取得します。 /// </summary> /// <param name="gridCell">DataGridViewのセルオブジェクト</param> /// <param name="range">設定対象セル</param> /// <returns>Excelの表示形式</returns> private void SetFormat(DataGridViewCell gridCell, ref dynamic range) { if (true == String.IsNullOrWhiteSpace(gridCell.Style.Format)) { return; } var valueType = gridCell.GetValueType(); string gridFormat = gridCell.Style.Format.Convert(format => format.Replace(@"\\", @"\")); string numberFormat = (true == valueType.IsNumeric()) ? this.GetNumericExcelFormt(gridFormat) : (typeof(DateTime) == valueType) ? this.GetDateTimeExcelFormt(gridFormat) : (typeof(string) == valueType) ? this.GetStringExcelFormt(gridFormat) : this.GetOtherExcelFormt(gridFormat); if (null != numberFormat) { range.NumberFormat = numberFormat; } return; }