我有一个桌面应用程序,在其中我从模板生成一个 excel 文件,基本上我所做的就是将模板 excel 文件的副本复制到一个新目录,打开它,然后向其中添加记录。
这是一个代码片段:
string ExcelFiles = txtFileOutput.Text; //Application.StartupPath + @"\ExcelFiles\";
string DestFile = ExcelFiles + FinalListOfTrucks[0].Date.ToShortDateString().Replace('/', '_') + ".xlsx";
if (File.Exists(DestFile))
{
try
{
File.Delete(DestFile);
}
catch (Exception ex)
{
MessageBox.Show("Error deleting file: " + ex.Message);
}
}
try
{
File.Copy(Application.StartupPath + @"\ExcelTemplate.xlsx", DestFile);
}
catch (Exception ex)
{
MessageBox.Show("Error copying file: " + ex.Message);
}
string appPath = Path.GetDirectoryName(Application.ExecutablePath);
string strConnectionXls = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + DestFile + ";Extended Properties=Excel 12.0;";
OleDbConnection cno = new OleDbConnection(strConnectionXls);
OleDbCommand cmo = new OleDbCommand();
cmo.Connection = cno;
cmo.CommandType = CommandType.Text;
string QueryHeader = "INSERT INTO [RptTotal$] (NUMERO,FECHA,JORNADA,PLACA,HORA_DE_LLEGADA,HORA_FIN_CARGUE,HORA_FIN_DESCARGUE,VOLUMEN,DISTANCIA,TIPO_DE_VEHICULO,MATERIAL,MISSED_DATE)";
cmo.CommandText = QueryHeader + " VALUES ('" + No.ToString() + "','" + Fecha + "','" + Jornada + "','" + Placa + "','" + HoraDeLlegada + "','" + HoraFinCargue + "','" +
HoraFinDescargue + "','" + Volumen + "','" + Distancia + "','" + TipoDeVehiculo + "','" + Material + "','" + MissedDate + "')";
cmo.ExecuteNonQuery();
现在,假设我可以向我的 webapp 添加一个文件夹,并将 excel 模板放在那里,如何从那里开始在 web :\ 中实现相同的功能?