public object Writexcel(FormNo formNo) { try { //Getting Base URL. string baseUrl = HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Authority + HttpContext.Current.Request.ApplicationPath.TrimEnd('/') + "/"; //Raw file path. string fileRawpath = ConfigurationManager.AppSettings.Get("FilePath"); //Complete file path. string filePath = HttpContext.Current.Server.MapPath(fileRawpath); //SaveAs file path. string saveAsPath = ConfigurationManager.AppSettings.Get("SaveAs"); //Complete file path. string saveAsFilePth = HttpContext.Current.Server.MapPath(saveAsPath); //convert path to url to download file. string downloadFile = baseUrl + saveAsPath; using (ExcelEngine excel = new ExcelEngine()) { //Instantiate the Excel application object IApplication application = excel.Excel; //Set the default application version application.DefaultVersion = ExcelVersion.Excel2016; //Load the existing Excel workbook into IWorkbook IWorkbook workbook = application.Workbooks.Open(filePath); //Get the first worksheet in the workbook into IWorksheet IWorksheet worksheet = workbook.Worksheets[0]; worksheet.Range["D5"].Text = formNo.NameAddress; worksheet.Range["D6"].Text = formNo.PAN; worksheet.Range["D7"].Text = formNo.FinancialYear; worksheet.Range["A47"].Text = "Place : " + formNo.Place; worksheet.Range["A48"].Text = "Date : " + formNo.Date; worksheet.Range["A49"].Text = "Designation : " + formNo.Designation; workbook.SaveAs(saveAsFilePth); } return(new { status = 1, message = downloadFile }); } catch (Exception ex) { return(new { status = 0, message = ex.Message }); } }
public IForm CreateForm(FormNo num) { switch (num) { case FormNo.Form1: return(new Form1()); case FormNo.Form2: return(new Form2()); case FormNo.Form3: return(new Form3()); default: return(new Form1()); } }
static void Main(string[] args) { //FormReimburseInvoiceTableAdapter taInvoice = new FormReimburseInvoiceTableAdapter(); //FormTableAdapter taForm = new FormTableAdapter(); //FormDS.FormReimburseInvoiceDataTable tbInvoice = taInvoice.GetData(); //foreach (FormDS.FormReimburseInvoiceRow item in tbInvoice) { // if (!item.IsSystemInfoNull()) { // string SystemInfo = item.SystemInfo; // string[] FormNos = SystemInfo.Split(','); // string RepeatFormStr = ""; // if (FormNos.Length > 0) { // foreach (string FormNo in FormNos) { // if (!string.IsNullOrEmpty(FormNo)) { // FormDS.FormDataTable tbForm = taForm.GetDataByFormNo(FormNo); // if (tbForm != null && tbForm.Count > 0) { // RepeatFormStr += "P" + tbForm[0].FormID + ":" + tbForm[0].FormNo + "P"; // } // } // } // } // item.SystemInfo = RepeatFormStr; // taInvoice.Update(item); // } //} //FormReimburseInvoiceTableAdapter taInvoice = new FormReimburseInvoiceTableAdapter(); //FormTableAdapter taForm = new FormTableAdapter(); //FormDS.FormReimburseInvoiceDataTable tbInvoice = taInvoice.GetData(); //foreach (FormDS.FormReimburseInvoiceRow item in tbInvoice) { // if (!item.IsSystemInfoNull()) { // string SystemInfo = item.SystemInfo; // SystemInfo = SystemInfo.Replace("PP", "P"); // string[] FormNos = SystemInfo.Split('P'); // string RepeatFormStr = ""; // if (FormNos.Length > 0) { // foreach (string FormNo in FormNos) { // if (!string.IsNullOrEmpty(FormNo)) { // FormDS.FormDataTable tbForm = taForm.GetDataByID(int.Parse(FormNo.Split(':')[0])); // if (tbForm != null && tbForm.Count > 0) { // RepeatFormStr += "P" + tbForm[0].FormID + ":" + tbForm[0].FormNo + "P"; // } // } // } // } // item.SystemInfo = RepeatFormStr; // taInvoice.Update(item); // } //} FormReimburseInvoiceTableAdapter taInvoice = new FormReimburseInvoiceTableAdapter(); FormTableAdapter taForm = new FormTableAdapter(); FormDS.FormReimburseInvoiceDataTable tbInvoice = taInvoice.GetData(); foreach (FormDS.FormReimburseInvoiceRow item in tbInvoice) { if (!item.IsSystemInfoNull()) { string SystemInfo = item.SystemInfo; SystemInfo = SystemInfo.Replace("PP", "P"); string[] FormNos = SystemInfo.Split('P'); string RepeatFormStr = ""; if (FormNos.Length > 0) { foreach (string FormNo in FormNos) { if (!string.IsNullOrEmpty(FormNo)) { FormDS.FormDataTable tbForm = taForm.GetDataByID(int.Parse(FormNo.Split(':')[0])); if (tbForm != null && tbForm.Count > 0) { RepeatFormStr += "P" + tbForm[0].FormID + ":" + tbForm[0].FormNo + ":" + tbForm[0].PageType + "P"; } } } } item.SystemInfo = RepeatFormStr; taInvoice.Update(item); } } }