0

LinqToExcel ライブラリを使用して、Excel ワークシートから個別の値を取得しようとしています。

エラーが発生し続けます

"{"クエリ式 '(MOD)' に構文エラー (演算子がありません)。"}"

私はすべてを試しましたが、この列から個別の値を引き出すことができないようです。

どんな援助でも大歓迎です。

前もって感謝します、

コードは次のとおりです。

public class WorksheetRow
{
    public String CPT { get; set; }
    public String MOD { get; set; }
    public String DESCRIPTION { get; set; }
    public double FEE { get; set; }
}

public class FileUtilsController : Controller
{
    //
    // GET: /FileUtils/

    public ActionResult Index()
    {
        return View();
    }

    public ActionResult FileUpload()
    {
            return View();


    }

    // This action handles the form POST and the upload
    [HttpPost]
    public ActionResult FileUpload(HttpPostedFileBase file)
    {
        // Verify that the user selected a file
        if (file != null && file.ContentLength > 0) 
        {
            // extract only the fielname
            var fileName = Path.GetFileName(file.FileName);
            // store the file inside ~/App_Data/uploads folder
            var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName);
            file.SaveAs(path);

            var excel = new ExcelQueryFactory(path);
            List<String> worksheetNames = excel.GetWorksheetNames().ToList();
            String FirstWorksheet = worksheetNames[0];
            //Query Column Names
            //The GetColumnNames() method can be used to retrieve the list of column names in a worksheet.
            IEnumerable<String> ProcCodeModifiers = (from row in excel.Worksheet<WorksheetRow>(FirstWorksheet)
                                                     where row.MOD != null
                                                     select row.MOD).Distinct();


            ViewData["Modifiers"] = "";
            foreach (String item in ProcCodeModifiers)
            {
                ViewData["Modifiers"] += item + ", ";
            }

            // redirect back to the index action to show the form once again
//                return RedirectToAction("Index", "Home");

        }

        return View();

    }
4

1 に答える 1

0

このエラーが発生する理由をさらに調査する必要がありますが、簡単な回避策は、Distinct() 操作を実行する前にクエリをリストに変換することです。

これがコード例です

IEnumerable<String> ProcCodeModifiers = (from row in excel.Worksheet<WorksheetRow>(FirstWorksheet)
                                         where row.MOD != null
                                         select row.MOD).ToList().Distinct();
于 2013-03-29T14:18:13.053 に答える