Hello,
Thanks for your inquiry.
I simulated your scenario and tested with the latest
Spire.Xls(Hotfix) Version:10.9.16, but did not find that int and double data were saved as text. Below is my test code and output. If you are using an older version, please download the latest version and try again.
- Code: Select all
Dim dt As DataTable = New DataTable
dt.Columns.Add("Country", Type.GetType("System.String"))
dt.Columns.Add("Jun", Type.GetType("System.Int32"))
dt.Columns.Add("Aug", Type.GetType("System.Double"))
dt.Rows.Add("Cuba", "6000", "32.00")
dt.Rows.Add("Mexico", "8000", "20.00")
dt.Rows.Add("France", "9000", "40.00")
dt.Rows.Add("German", "8500", "23.00")
Me.DataGridView1.DataSource = dt
Dim workbook As Spire.Xls.Workbook = New Spire.Xls.Workbook
Dim sheet As Spire.Xls.Worksheet = workbook.Worksheets(0)
sheet.InsertDataTable(DataGridView1.DataSource, False, 1, 1)
workbook.SaveToFile("result.xlsx", FileFormat.Version2013)
- screenshot.png (5.78 KiB) Viewed 753 times
In addition, we also provide a direct method to convert Text to Number, below is the corresponding code for your reference.
- Code: Select all
sheet.Range("A2").ConvertToNumber()
Sincerely,
Elena
E-iceblue support team