Export excel paramétrer filename
Bonjour,
Dans mon application Web, j'ai une dropdown permettant de sélectionner une company.
Après la sélection de la company, il y a la possibilité de faire un export d'un fichier excel.
Tout fonctionne mais je bloque sur un point : paramétrer le nom de mon fichier excel en lui donnant le nom de la company sélectionné.
Le code pour l'export Excel :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| public class BLConstants
{
public static readonly string Reset_Password_Status = "InitPassword";
public static readonly string HelpFilePath = "~/Content/Documents";
public static readonly string HelpFileContentType = "application/pdf";
public static readonly int ControlFirstDataLine = 4;
public static readonly string ControlTemplate = "~/Content/Documents/ControlTemplate.xlsx";
public static readonly string ControlTemplateContentType = "application/vnd.ms-excel.12";
public static readonly string ControlTemplateFileName = "Controls.xlsx";
public static readonly int RegulationFirstDataLine = 4;
public static readonly string RegulationTemplate = "~/Content/Documents/RegulationTemplate.xlsx";
public static readonly string RegulationTemplateContentType = "application/vnd.ms-excel.12";
public static readonly string RegulationTemplateFileName = "Regulations.xlsx";
} |
Le post :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
[HttpPost]
[ValidateAntiForgeryToken]
public FileStreamResult _ControlsExport(ControlsExportModel model)
{
try
{
if (!ModelState.IsValid)
//TODO
return null;
LoggingService.Write(string.Format("Exporting the controls for the company ID: {0}", model.SelectedCompany));
int parsedId;
if (!int.TryParse(model.SelectedCompany, out parsedId))
throw new ArgumentException("model.SelectedCompany is not an int.");
var data = ContextDataService.GetModuleExportData(parsedId);
var stream = ExcelService.ExportModule(data);
return File(stream, BLConstants.ControlTemplateContentType, BLConstants.ControlTemplateFileName);
}
catch (Exception e)
{
throw new ApplicationException("Error in AdminController._ControlsExport(ControlsExportModel model)", e);
}
} |
Au niveau de ma vue / dropdown :
Code:
1 2 3 4 5 6 7 8 9 10
|
<select>
<label for="companySelect">ADMIN_CTRL_EXPORT_COMPANY</label>
<select id="SelectedCompany" class="ui-state-valid" name="SelectedCompany">
<option>Select a company</option>
<option value="1">Company1</option>
<option value="2">Company2</option>
<option value="3">Company3</option>
</select>
</select> |
Tout fonctionne, mais j'aimerais paramétrer le nom du fichier d'export excel en fonction de la company choisie.
J'ai essayé de cette façon :
Code:
1 2
|
public static readonly string ControlTemplateFileName = ApplicationWeb.Entities.Company + ".xlsx"; |
Mais j'ai l'erreur :
"ApplicationWeb.Entities.Company" is a 'type', which is not valid in the given context.
Je ne comprends pas pourquoi j'ai cette erreur...
Une idée sur le problème ? Ou la meilleur façon de m'y prendre ?