ASP.NET-VB错误:表达式是一个值,因此不能成为赋值的目标 [英] ASP.NET- VB Error: Expression is a value and therefore cannot be the target of an assignment

查看:80
本文介绍了ASP.NET-VB错误:表达式是一个值,因此不能成为赋值的目标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好答案.我的解决方案不允许ASP.NET访问Office对象:((<
我们的环境...


现在回到方格1.尝试将网格结果加载到Excel中.您对我如何将结果发送到数据集有建议吗?



当我尝试将网格结果分配给excel工作表时,我不明白为什么收到消息表达式是一个值,因此不能成为赋值的目标".

Good Answer. My solution won''t allow ASP.NET to access office objects :((

Our environment...


Now I''m back to square 1. trying to get the grid results to load into Excel. Do you have a suggestion on how I could send the results to a data set?



I don''t understand why I''m getting the message "Expression is a value and therefore cannot be the target of an assignment" when I try to assign the grid results to an excel sheet.

Private Sub ibtnExcel_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ibtnExcel.Click
        imgSearch.Visible = False
        imgClear.Visible = False
        imgAdd.Visible = False
        imgApply.Visible = False
        ibtnExcel.Visible = False
        ibtnVersion.Visible = False
        ibtnHelp.Visible = False

        _strstyleSheet = ""


        Dim i, j As Integer
        Dim xlApp As Excel.Application
        Dim xlSht As Excel.Worksheet
        Dim rng As Excel.Range

        xlApp = New Excel._ExcelApplication
        xlApp.DisplayAlerts = False

        xlApp.Workbooks.Add()

        xlSht = CType(xlApp.Sheets(1), Excel.Worksheet)
        xlSht.Name = "BDIS-Download"

        Dim dc As DataColumn
        Dim dr As DataRow


        For i = 0 To grdResult.Columns.Count - 1
            xlSht.Cells(i + 1).value = grdResult.Columns(i)      
        Next

        With xlSht
            rng = CType(.Columns(1), Excel.Range)
            rng.AutoFit()
        End With

        xlApp.ActiveWorkbook.Close(True, "C:\BDISTest.xls")
        xlApp.Quit()

        ReleaseComObject(rng)
        ReleaseComObject(xlSht)
        ReleaseComObject(xlApp)

    End Sub

推荐答案

好吧,您用Google搜索错误消息了吗?

http://msdn.microsoft.com/en-us/library/76435b93% 28VS.80%29.aspx [ ^ ]
Well, did you google the error message?

http://msdn.microsoft.com/en-us/library/76435b93%28VS.80%29.aspx[^]


示例 [<我见过的a href ="http://support.microsoft.com/kb/302084" target ="_ blank" title ="New Window"> ^ ]指的是"value2",读取代码;

The examples[^] that I''ve seen refer to "value2", making your code read;

xlSht.Cells(i + 1).Value2 = grdResult.Columns(i)


也许您需要指定xlSht.Cells(i+1).Value或类似的内容(甚至可能需要将其从对象转换为特定类型).
Maybe you need to specify xlSht.Cells(i+1).Value or something like that (and you may even need to cast it from an object to a specific type).


这篇关于ASP.NET-VB错误:表达式是一个值,因此不能成为赋值的目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆