Reputation: 23
I would like to upload excel file to server and this excel have only a sheet so when copy to server i want to change sheet name to a fixed name because user upload this file every months and sheet name that user set is by month too so i would like to rename file when upload to fixed ex: sheet name before upload is 'nov2015' when upload change name to 'data'
note:
I use c# language to upload and rename file but not use excel interop library and i have code upload file below:
FolderPath = "~/Uploads/";
FileName = Path.GetFileName(fupload.PostedFile.FileName);
strFileType = Path.GetExtension(fupload.FileName).ToLower();
input_by = Session["user"].ToString();
FilePath = Server.MapPath(FolderPath + input_by + strFileType);
File.Delete(FilePath);
fupload.SaveAs(FilePath);
Upvotes: 1
Views: 2069
Reputation: 9739
Consider using NPOI for this. You can change the worksheet name like -
Workbook workbook = new HSSFWorkbook();
Worksheet sheet = (Worksheet)workbook.Worksheets[index];
//Change the name of worksheet
sheet.Name = "NewWorksheetName";
For more details, visit NPOI at gitHub. You can also find variety of examples here on various usage of the tool -
https://github.com/tonyqus/npoi
Upvotes: 2