Justin Weng wrote:Dear gacanepa,
Thanks for your inquiry and supporting our product.
We will be the study of your problem.
It's interesting that how did you load your .xlsx file.
Would you like upload a demo/code to me, I'll be appreciated.
Justin,
Here's what's inside the click event of the button that is used to browse for .xls or .xlsx files:
- Code: Select all
OpenFileDialog dlg = new OpenFileDialog();
dlg.Filter = "Excel 2003/2007 files|*.xls;*.xlsx";
DialogResult dlgResult = dlg.ShowDialog();
if (dlgResult == DialogResult.OK)
{
txtPath.Text = dlg.FileName; // txtPath is a text box that will show the file's location
}
Next, there is a "Load file" button with the following code inside its click event:
- Code: Select all
if (System.IO.File.Exists(txtPath.Text))
{
string connectionString = String.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=""Excel 8.0;HDR=YES;IMEX=1;""", txtPath.Text);
string query = String.Format("select * from [{0}$]", "Sheet2"); //it loads the data found in Sheet2, but you can set it to any sheet you want
OleDbDataAdapter dataAdapter = new OleDbDataAdapter(query, connectionString);
DataSet dataset = new DataSet();
dataAdapter.Fill(dataset);
dataGridView1.DataSource = dataset.Tables[0];
}
Then it exports the file:
- Code: Select all
Spire.DataExport.DBF.DBFExport DBFExport = new Spire.DataExport.DBF.DBFExport();
DBFExport.DataSource = Spire.DataExport.Common.ExportSource.DataTable;
DBFExport.DataTable = this.dataGridView1.DataSource as DataTable;
dataGridView1.Columns[2].DefaultCellStyle.Format = "0.00";
DBFExport.DefaultFloatDecimal = 3;
DBFExport.ExportIfEmpty = true;
DBFExport.AutoFitColWidth = true;
DBFExport.FileName = "C:\\Documents and Settings\\...\\whatever.dbf";
try
{
DBFExport.SaveToFile();
MessageBox.Show("Success.", "Notice: ", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch
{
MessageBox.Show("Fail", "Warning: ", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
It works like a charm! I hope you will find my experience useful, as I have found your component.
I'm still trying to find a workaround so that I can export some columns with 3 decimal figures and others with none. Let me know if you find out anything. Thanks!