Пример #1
0
        void ProcessExcel(string fileName, Dictionary <int, int> data)
        {
            //fileName = @"C:\Users\Mushfikur Rahman\Downloads\Technical-Adaptive Assessment.xlsx";

            //Microsoft.Office.Interop.Excel.Application excelAppObj = new Microsoft.Office.Interop.Excel.Application();
            //excelAppObj.DisplayAlerts = false;

            //Open the excel work book
            //Microsoft.Office.Interop.Excel.Workbook workBook = excelAppObj.Workbooks.Open(fileName, 0, false, 5, "", "", false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "", true, false, 0, false, false);

            //Get the first sheet of the selected work book
            //Microsoft.Office.Interop.Excel.Worksheet worksheet = (Microsoft.Office.Interop.Excel.Worksheet)workBook.Worksheets.get_Item(1);
            //ExcelWorkbook workBook = ExcelWorkbook.ReadXLSX(fileName);
            //var worksheet = workBook.Worksheets[0];

            //Book workbook = new BinBook();
            //workbook.load(fileName);


            //var worksheet = workbook.getSheet(0);
            Workbook workbook = new DevExpress.Spreadsheet.Workbook();

            workbook.LoadDocument(fileName);
            Worksheet worksheet = workbook.Worksheets[0];



            //Write 20 in Cell - C3
            //worksheet.Cells[4, 4].Value = txtName.Text;

            //worksheet.Cells[30, 3].Value = txtCompany.Text + ", " + txtEmail.Text;

            //worksheet.writeStr(4, 4, txtName.Text);


            //worksheet.writeStr(30, 3, txtCompany.Text + ", " + txtEmail.Text);


            worksheet.Cells[4, 2].Value = txtName.Text;
            //worksheet.Cells[29, 2].Value = txtCompany.Text + ", " + txtEmail.Text;

            int technical = 0;
            int adaptive  = 0;

            var technicalResult = 0D;
            var adaptiveResult  = 0D;


            var curRow = 6;

            foreach (var item in data)
            {
                if (item.Value == 0)
                {
                    worksheet.Cells[curRow, 3].Value = 1;
                    //technical++;
                }
                //worksheet.writeNum(curRow, 5, 1);
                else if (item.Value == 1)
                {
                    worksheet.Cells[curRow + 1, 3].Value = 1;
                    //adaptive++;
                }
                else if (item.Value == 2)
                {
                    worksheet.Cells[curRow + 2, 3].Value = 1;
                }
                else
                {
                    worksheet.Cells[curRow + 3, 3].Value = 1;
                }
                //worksheet.writeNum(curRow + 1, 5, 1);

                curRow += 4;
            }

            //technicalResult = (technical / 12) * 100;
            //adaptiveResult = (adaptive / 12) * 100;

            //Save work book (.xlsx format)
            //workBook.SaveAs(fileName, Microsoft.Office.Interop.Excel.XlFileFormat.xlOpenXMLWorkbook, null, null, false,
            //false, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlShared, false, false, null, null, null);

            //excelAppObj.Quit();
            //workBook.WriteXLSX(fileName);
            //workbook.save(fileName);

            workbook.AddService(typeof(IChartControllerFactoryService), new ChartControllerFactoryService());
            workbook.AddService(typeof(IChartImageService), new ChartImageService());

            workbook.SaveDocument(fileName);

            var pdfFileName = fileName.Replace(".xlsx", ".pdf");

            workbook.ExportToPdf(pdfFileName);
            Session["ReportFilePath"] = pdfFileName;
            //workbook.ExportToHtml(fileName + ".pdf", 1);

            //Save to downloads//
            var reportID = ins.SaveDownloads(int.Parse(Session["userId"].ToString()), "Leadership Complexities", pdfFileName);

            Session["ReportID"] = reportID;


            string errorFileName = Server.MapPath("~") + @"\Files\Docx\EmailError.txt";

            var res         = 1; Basics.email_send(fileName.Replace(".xlsx", ".pdf"), string.Format("Leadership Complexities Assessment - {0}-{1}", txtName.Text, txtCompany.Text), "Your assessment report is ready to download.", txtEmail.Text, errorFileName);
            var CurrentPage = GetCurrentPageName();

            ins.DeleteHolt(int.Parse(Session["userId"].ToString()), CurrentPage);
            ins.DeleteAnsState(CurrentPage, int.Parse(Session["userId"].ToString()));
            if (res == 1)
            {
                Response.Redirect("Home.aspx");
            }
            else
            {
                Response.Redirect("Error.aspx");
            }
        }
        void ProcessExcel(string fileName, Dictionary <int, int> data)
        {
            //fileName = @"C:\Users\Mushfikur Rahman\Downloads\Technical-Adaptive Assessment.xlsx";

            //Microsoft.Office.Interop.Excel.Application excelAppObj = new Microsoft.Office.Interop.Excel.Application();
            //excelAppObj.DisplayAlerts = false;

            //Open the excel work book
            //Microsoft.Office.Interop.Excel.Workbook workBook = excelAppObj.Workbooks.Open(fileName, 0, false, 5, "", "", false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "", true, false, 0, false, false);

            //Get the first sheet of the selected work book
            //Microsoft.Office.Interop.Excel.Worksheet worksheet = (Microsoft.Office.Interop.Excel.Worksheet)workBook.Worksheets.get_Item(1);
            //ExcelWorkbook workBook = ExcelWorkbook.ReadXLSX(fileName);
            //var worksheet = workBook.Worksheets[0];

            //Book workbook = new BinBook();
            //workbook.load(fileName);


            //var worksheet = workbook.getSheet(0);
            Workbook workbook = new DevExpress.Spreadsheet.Workbook();

            workbook.LoadDocument(fileName);
            Worksheet worksheet = workbook.Worksheets[0];


            //Write 20 in Cell - C3
            //worksheet.Cells[4, 4].Value = txtName.Text;

            //worksheet.Cells[30, 3].Value = txtCompany.Text + ", " + txtEmail.Text;

            //worksheet.writeStr(4, 4, txtName.Text);


            //worksheet.writeStr(30, 3, txtCompany.Text + ", " + txtEmail.Text);


            worksheet.Cells[3, 3].Value  = txtName.Text;
            worksheet.Cells[29, 2].Value = txtCompany.Text + ", " + txtEmail.Text;

            int technical = 0;
            int adaptive  = 0;

            var technicalResult = 0D;
            var adaptiveResult  = 0D;


            var curRow = 5;

            foreach (var item in data)
            {
                if (item.Value == 0)
                {
                    worksheet.Cells[curRow, 4].Value = 1;
                    technical++;
                }
                //worksheet.writeNum(curRow, 5, 1);
                else
                {
                    worksheet.Cells[curRow + 1, 4].Value = 1;
                    adaptive++;
                }
                //worksheet.writeNum(curRow + 1, 5, 1);

                curRow += 2;
            }

            technicalResult = (technical / 12) * 100;
            adaptiveResult  = (adaptive / 12) * 100;

            //Save work book (.xlsx format)
            //workBook.SaveAs(fileName, Microsoft.Office.Interop.Excel.XlFileFormat.xlOpenXMLWorkbook, null, null, false,
            //false, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlShared, false, false, null, null, null);

            //excelAppObj.Quit();
            //workBook.WriteXLSX(fileName);
            //workbook.save(fileName);
            workbook.SaveDocument(fileName);

            workbook.ExportToPdf(fileName + ".pdf");

            var res = Basics.email_send(fileName, string.Format("Technical Adaptive Assessment Submission - {0}-{1}", txtName.Text, txtCompany.Text), "A new assessment has been submitted.");

            if (res == 1)
            {
                Response.Redirect("Home.aspx");
            }
            else
            {
                Response.Redirect("Error.aspx");
            }
        }