List<JSW_JHD> list = new List<JSW_JHD>();
string[] ids = id.Split(',');
for (int i = 0; i < ids.Length; i++)
{
//根据bh编号查询
JSW_JHD emp = companyService.getalljsw_jhdbybh(ids[i].ToString());
list.Add(emp);
}
Excel.Application app = new Microsoft.Office.Interop.Excel.Application();
//设置是否打开Excel
app.Visible = true;
//创建工作簿(添加一张新的工作表簿)
Excel.Workbook wb = app.Workbooks.Add(Excel.XlWBATemplate.xlWBATWorksheet);
//创建列名
app.Cells[1, 1] = "日期";
app.Cells[1, 2] = "对方单位";
app.Cells[1, 3] = "入库";
app.Cells[1, 4] = "对方经办";
app.Cells[1, 5] = "仓库";
app.Cells[1, 6] = "入库单号";
app.Cells[1, 7] = "我方经办";
app.Cells[1, 8] = "到货时间";
app.Cells[1, 9] = "运输方式";
app.Cells[1, 10] = "物流公司";
app.Cells[1, 11] = "审核人员";
app.Cells[1, 12] = "审核时间";
app.Cells[1, 13] = "审核级别";
int j = 2;//行从第二行开始
foreach (var item in list)
{
app.Cells[j, 1] = item.DJRQ;
app.Cells[j, 2] = item.DFDW;
app.Cells[j, 3] = item.RKQK;
app.Cells[j, 4] = item.DFJB;
app.Cells[j, 5] = item.CKBH;
app.Cells[j, 6] = item.RKDH;
app.Cells[j, 7] = item.WFJB;
app.Cells[j, 8] = item.DHSJ;
app.Cells[j, 9] = item.YSFS;
app.Cells[j, 10] = item.WLGS;
app.Cells[j, 11] = item.SHRY;
app.Cells[j, 12] = item.SHSJ;
app.Cells[j, 13] = item.XSJB;
j++;//行加一
}
//保存修改
//SaveFileDialog fileDlg = new SaveFileDialog();
// fileDlg.Filter = "csv files (*.csv)|*.csv|All files (*.*)|*.*";
// fileDlg.FilterIndex = 1;
// fileDlg.RestoreDirectory = true;
// if (fileDlg.ShowDialog() == DialogResult.OK)
// {
// if(File.Exists(fileDlg.FileName))
// File.Delete(fileDlg.FileName);
//引用excel工作薄
//保存
wb.SaveAs(string.Format(@"E:\调达计划信息表" + DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day + "-" + DateTime.Now.Hour + "-" + DateTime.Now.Minute + "-" + DateTime.Now.Second), Excel.XlFileFormat.xlWorkbookNormal, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Excel.XlSaveAsAccessMode.xlExclusive, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
//释放资源
wb = null;
app.Quit();
app = null;
return "ok";
我是硬写在E盘的,这样不好。让用户自己选择路径 我是硬写在E:\调达计划信息表加时间的我是想让用户自己选择路径。怎么弹出个用户选择路径的框 在点击保存
/// <summary>
/// 选择保存htm文件的文件夹
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button2_Click(object sender, EventArgs e)
{
FolderBrowserDialog folderBrowserDialog1 = new FolderBrowserDialog();
folderBrowserDialog1.Description = "请选择保存htm文件的文件夹";
//folderBrowserDialog1.ShowNewFolderButton = true;
//folderBrowserDialog1.RootFolder = Environment.SpecialFolder.Personal;
DialogResult result = folderBrowserDialog1.ShowDialog();
if (result == DialogResult.OK)
{
string folderName = folderBrowserDialog1.SelectedPath;
if (folderName != "")
{
textBox1.Text = folderName;
SaveHtmPath_EXCEL = textBox1.Text;
}
}
}
不知道这是不是你要的。
您的这段代码 应该是Server端的代码吧,把Server上面的路径开放给Client端看的话,需要传送数据到Client端的javascript代码上啊, 而且也不够安全啊,服务器端是没法设置Client端的文件位置什么的。服务器上面的对话框什么的客户端是看不到的。
根本就不对
最佳答案那个也是醉了,人家问的是MVC,你整一个窗体应用程序的方法