gpt4 book ai didi

c# - 在 C# 中创建一个库类

转载 作者:行者123 更新时间:2023-11-30 22:20:07 26 4
gpt4 key购买 nike

我对此很陌生,我需要一些帮助将方法转换为库类以用作 dll。我的问题是如何处理我用来获取从用户传入的数据的文本框值。

这是我正在使用并希望作为可用库类的方法:

public Microsoft.Office.Interop.Excel.Workbook excelWorkbook { get; set; }
void ExcelToPdf(string convertFilePath)
{
Microsoft.Office.Interop.Excel.Application appWord = new Microsoft.Office.Interop.Excel.Application();
excelWorkbook = appWord.Workbooks.Open(DocumentUNCPath.Text);

excelWorkbook.ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, convertFilePath);
excelWorkbook.Close();
appWord.Quit();
}

最佳答案

因此,当您将其移动到库中时,您需要将这些值注入(inject)到方法中:

public Microsoft.Office.Interop.Excel.Workbook excelWorkbook { get; set; }

void ExcelToPdf(string convertFilePath, string documentUncPath)
{
Microsoft.Office.Interop.Excel.Application appWord = new Microsoft.Office.Interop.Excel.Application();
excelWorkbook = appWord.Workbooks.Open(documentUncPath); // WAS DocumentUNCPath.Text

excelWorkbook.ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, convertFilePath);
excelWorkbook.Close();
appWord.Quit();
}

因此,当您调用该方法时,您将从表单中传入 DocumentUNCPath.Text 的值。

关于c# - 在 C# 中创建一个库类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15143720/

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