我有一个桌面应用程序,我从模板中生成一个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中实现相同的功能:\?