【问题标题】:The left-hand side of an assignment must be a variable, property or indexer comes in my code [duplicate]赋值的左侧必须是我的代码中的变量、属性或索引器[重复]
【发布时间】:2018-05-15 10:17:38
【问题描述】:
            Microsoft.Office.Interop.Excel.Application xlApp;
            Microsoft.Office.Interop.Excel.Workbook xlWorkBook;
            Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet;

            xlApp = new Microsoft.Office.Interop.Excel.ApplicationClass();
            xlWorkBook = xlApp.Workbooks.Add(Type.Missing);
            xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
            int i = 0;
            int j = 0;
            if (dgvSearchStudFees.Visible == true)
            {
                for (i = 0; i <= dgvSearchStudFees.RowCount - 1; i++)
                {
                    for (j = 0; j <= dgvSearchStudFees.ColumnCount - 1; j++)
                    {
                        DataGridViewCell cell = dgvSearchStudFees[j, i];
                        xlWorkSheet.Cells[i + 1, j + 1] = cell.Value;
                    }
                }
                var savefiledialog = new SaveFileDialog();
                savefiledialog.FileName = "Atharva ExcelSheet";
                savefiledialog.DefaultExt = ".xlsx";
                if (savefiledialog.ShowDialog()=DialogResult.OK)   // here I m getting an error "The left-hand side of an assignment must be a variable, property or indexer" Don't know what is wrong. Same as above If statement. its a code for exporting the Data Grid View data to Microsoft excel. I tried doing this code but still I don't understand why this error occurs.
                {
                    xlWorkBook.SaveAs(savefiledialog.FileName, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
                }
                xlApp.Quit();
            }

请帮我处理这段代码。

【问题讨论】:

  • = => ==....
  • 应该是 == 不是 =

标签: c#


【解决方案1】:
        Microsoft.Office.Interop.Excel.Application xlApp;
        Microsoft.Office.Interop.Excel.Workbook xlWorkBook;
        Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet;

        xlApp = new Microsoft.Office.Interop.Excel.ApplicationClass();
        xlWorkBook = xlApp.Workbooks.Add(Type.Missing);
        xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
        int i = 0;
        int j = 0;
        if (dgvSearchStudFees.Visible == true)
        {
            for (i = 0; i <= dgvSearchStudFees.RowCount - 1; i++)
            {
                for (j = 0; j <= dgvSearchStudFees.ColumnCount - 1; j++)
                {
                    DataGridViewCell cell = dgvSearchStudFees[j, i];
                    xlWorkSheet.Cells[i + 1, j + 1] = cell.Value;
                }
            }
            var savefiledialog = new SaveFileDialog();
            savefiledialog.FileName = "Atharva ExcelSheet";
            savefiledialog.DefaultExt = ".xlsx";
            if (savefiledialog.ShowDialog() == DialogResult.OK)   // This should be == . "=" means assignment to left hand side
            {
                xlWorkBook.SaveAs(savefiledialog.FileName, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
            }
            xlApp.Quit();
        }

【讨论】:

    猜你喜欢
    • 2015-07-07
    • 1970-01-01
    • 2017-05-28
    • 2016-05-09
    • 2018-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-29
    相关资源
    最近更新 更多