当前位置:  开发笔记 > 编程语言 > 正文

类型或命名空间定义,或具有相同括号数的文件结束预期错误

如何解决《类型或命名空间定义,或具有相同括号数的文件结束预期错误》经验,为你挑选了1个好方法。

嗨,我在将VB程序转换为C#后得到了这个提到的错误,但我似乎无法找到丢失的右括号.我多次计算它们,在我看来,我有相同数量,但我也一直在寻找.这是我正在使用的代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Office.Interop.Excel;
using System.Text.RegularExpressions;

public class Class1
{
public Class1()
{
    private void exportData(DataTable dt, string workpath, string tabName, bool isStmt = false)
    {
        if (dt.Rows.Count > 0 && IO.File.Exists(workpath)) 
        {
            //export data to excel
            exportExcel = true;

            Microsoft.Office.Interop.Excel.Workbook NewWorkbook = default(Microsoft.Office.Interop.Excel.Workbook);
            Microsoft.Office.Interop.Excel.Style style = default(Microsoft.Office.Interop.Excel.Style);
            Microsoft.Office.Interop.Excel.Worksheet CurrentSheet = new Microsoft.Office.Interop.Excel.Worksheet();
            Microsoft.Office.Interop.Excel.Worksheet totalWorkSheets = default(Microsoft.Office.Interop.Excel.Worksheet);
            string excelSheetNames = null;

            if (IO.File.Exists(workpath)) 
            {
                //file exists
                NewWorkbook = Form1.newExcel.Workbooks.Open(workpath);
            } 
            else 
            {
                //file does not exist; create new file
                NewWorkbook = Form1.newExcel.Workbooks.Add();
                style = NewWorkbook.Styles.Add("Style1");
                style.NumberFormat = "@";
            }

            //get all tab names
            foreach (var totalWorkSheets in NewWorkbook.Worksheets) 
            {
                excelSheetNames += totalWorkSheets.Name;
            }

            //does tab exist?
            if (Strings.InStr(excelSheetNames, tabName) > 0) 
            {
                //write to tab
                CurrentSheet = NewWorkbook.Worksheets(tabName);
            } 
            else 
            {
                //create new tab
                CurrentSheet = NewWorkbook.Worksheets.Add();
                CurrentSheet.Name = tabName;
            }

            CurrentSheet.Activate();

            int currentRow = 1;

            //LOAN TYPE
            //ACCOUNT NUMBER
            //CUSTOMER NAME
            //SSN
            //OPEN DATE
            //CHARGE OFF DATE
            //PLACEMENT/SALE DATE
            //RANGE FROM
            //RANGE TO
            //TOTAL REQUESTED

            //FILL EXCEL DATA
            foreach (DataRow row in dt.Rows) 
            {
                currentRow = currentRow + 1;

                CurrentSheet.Cells(currentRow, 1) = row.Item("BUCKET").ToString;
                //LOAN TYPE
                CurrentSheet.Cells(currentRow, 2) = row.Item("ACCOUNT NUMBER").ToString;
                //ACCOUNT NUMBER
                CurrentSheet.Cells(currentRow, 3) = row.Item("CUSTOMER NAME").ToString;
                //CUSTOMER NAME
                CurrentSheet.Cells(currentRow, 4) = row.Item("SS_#").ToString().Replace("-", "").ToString;
                //SSN
                CurrentSheet.Cells(currentRow, 5) = row.Item("OPEN DATE").ToString;
                //OPEN DATE

                if (isStmt) 
                {
                    CurrentSheet.Cells(currentRow, 6) = row.Item("CHARGE OFF DATE").ToString;
                    //CHGOFF DATE
                } 
                else 
                {
                    CurrentSheet.Cells(currentRow, 6) = row.Item("CHGOFF_DATE").ToString;
                    //CHGOFF DATE
                }

                CurrentSheet.Cells(currentRow, 7) = row.Item("SALE DATE").ToString;
                //SALE DATE

                if (isStmt) 
                {
                    CurrentSheet.Cells(currentRow, 8) = row.Item("STATEMENT FROM").ToString;
                    //STMT FROM
                    CurrentSheet.Cells(currentRow, 9) = row.Item("STATEMENT TO").ToString;
                    //STMT TO
                }

                CurrentSheet.Cells(currentRow, 10) = row.Item("ITEMS_REQUESTED").ToString;
            }
            //END EXCEL DATA STREAM

            if (IO.File.Exists(workpath)) 
            {
                NewWorkbook.Save();
            } 
            else 
            {
                NewWorkbook.SaveAs(workpath);
            }
            NewWorkbook.Close();

            System.Runtime.InteropServices.Marshal.ReleaseComObject(CurrentSheet);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(NewWorkbook);

            CurrentSheet = null;
            NewWorkbook = null;

        }
    }
}
}

Reed Copsey.. 7

您将方法放在构造函数中:

public class Class1
{
public Class1()
{
// Missing close brace here!!!

    private void exportData(DataTable dt, string workpath, string tabName, bool isStmt = false)
    {

这也意味着你最终需要从末端移除一个额外的支撑.



1> Reed Copsey..:

您将方法放在构造函数中:

public class Class1
{
public Class1()
{
// Missing close brace here!!!

    private void exportData(DataTable dt, string workpath, string tabName, bool isStmt = false)
    {

这也意味着你最终需要从末端移除一个额外的支撑.

推荐阅读
TXCWB_523
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有