예제 #1
0
        public ActionResult PreviewerForExcel(FormCollection form)
        {
            VmPreviewerForExcel ViewModel   = new VmPreviewerForExcel();
            ConvertService      ConvertServ = new ConvertService();

            //掃描目標資料夾並取出列表放在下拉式選單中
            string SelectedItem = (!string.IsNullOrEmpty(form["select-file-or-directory"])) ? Path.GetFileName(form["select-file-or-directory"]) : string.Empty;

            ViewModel.FileSelectList = ConvertServ.GetSelectList(GlobalVars.LOADING_FILES_EXCEL, "*.xls*", SearchOption.AllDirectories);

            //取得索引並轉換目標檔案
            if (Request.RequestType == "POST" && !string.IsNullOrEmpty(SelectedItem))
            {
                ViewModel.FileSelectList.Find(x => x.Text == SelectedItem).Selected = true;

                string ConvertPath = ViewModel.FileSelectList.Single(x => x.Text == SelectedItem).Value;
                ViewModel.SheetList = ConvertServ.GetObjectFromExcelFile(ConvertPath);
            }

            return(View(ViewModel));
        }