我有这段代码,是从excel中的数据表导出数据,我想做的是自己在@“”中写入位置,我想让用户自己选择位置,谢谢。
DataTable dt = hpl.SearchUserGroup(Convert.ToInt32(txtSearch.Text));
Workbook book = new Workbook();
Worksheet sheet = book.Worksheets[0];
sheet.InsertDataTable(dt, true, 1, 1);
book.SaveToFile(@"", ExcelVersion.Version97to2003);
最佳答案
您可能需要如下所示的内容。 我没有机会在 Visual Studio 中对此进行测试
string folderPath = string.Empty;
DataTable dt = hpl.SearchUserGroup(Convert.ToInt32(txtSearch.Text));
Workbook book = new Workbook();
Worksheet sheet = book.Worksheets[0];
sheet.InsertDataTable(dt, true, 1, 1);
using(var folderLoc = new FolderBrowserDialog())
{
DialogResult dlgResult = folderLoc.ShowDialog();
if (dlgResult == DialogResult.OK )
{
folderPath = folderLoc.SelectedPath;
}
}
//create a temp file with .xls extension
folderPath += Path.GetTempFileName().Replace(".tmp", ".xls");
book.SaveToFile(folderPath, ExcelVersion.Version97to2003);
如果您遇到任何问题,请告诉我。
关于c# - 如何让用户在 C# 中选择文件位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47513109/