gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 17:40:58 24 4
gpt4 key购买 nike

您好,我在将 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;

}
}
}
}

最佳答案

你把这些方法放在你的构造函数中:

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

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

这也意味着您最终需要从末端移除一个额外的支架。

关于c# - 类型或命名空间定义,或具有相同数量括号的文件结束预期错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22719384/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com