我希望将我的代码从Microsoft Office Interop OWC11更改为Spread Sheet Gear。 但是,我在代码中遇到了一些问题。这里显示的代码是使用Microsoft.Office.Interop.Owc11,我尝试使用Spread Sheet Gear和一些IWorkBook,IWorkSheet,使用SpreadsheetGear;但我仍然无法改变并得到错误,使我的文件凌乱。你可以帮我解决这个问题吗? 将以下代码更改为SpreadsheetGear
TemplateManagerBLTest.cs
using Microsoft.Office.Interop.Owc11;
public void FindRangeTest()
{
TemplateManagerBL target = new TemplateManagerBL();
TestBusinessLogic.BusinessLogic_TemplateManagerBLAccessor accessor = new TestBusinessLogic.BusinessLogic_TemplateManagerBLAccessor(target);
string rangeKeyword = "END";
AxSpreadsheet currentSpreadSheet = GetTestSheet("..\\..\\..\\TestBusinessLogic\\TemplateManagerTestData\\TEST_TemplateForGetRangeTest.xml");
int expectedCol, expectedRow;
expectedCol = 1;
expectedRow = 306;
TemplateManagerBL.Coordinate actual;
actual = accessor.FindRange(rangeKeyword, currentSpreadSheet);
Assert.AreEqual(expectedCol, actual.Column, "FindRange did not return the expected column value.");
Assert.AreEqual(expectedRow, actual.Row, "FindRange did not return the expected column value.");
}
GetTestSheet内部
#region "Test Data Methods"
private AxMicrosoft.Office.Interop.Owc11.AxSpreadsheet GetTestSheet(string filePath)
{
AxMicrosoft.Office.Interop.Owc11.AxSpreadsheet currentSpreadSheet;
string tXML = "";
TextReader textReader = new StreamReader(@filePath);
while (textReader.ReadLine() != null)
{
tXML = textReader.ReadToEnd();
}
TemplateControl tc = new TemplateControl();
currentSpreadSheet = new AxMicrosoft.Office.Interop.Owc11.AxSpreadsheet();
currentSpreadSheet = tc.SpreadSheet;
currentSpreadSheet.XMLData = tXML;
return currentSpreadSheet;
}
在FindRange中
internal global::BusinessLogic.TemplateManagerBL.Coordinate FindRange(string rangeKeyword, global::AxMicrosoft.Office.Interop.Owc11.AxSpreadsheet currentSpreadSheet)
{
object[] args = new object[] {
rangeKeyword,
currentSpreadSheet};
global::BusinessLogic.TemplateManagerBL.Coordinate ret = ((global::BusinessLogic.TemplateManagerBL.Coordinate)(m_privateObject.Invoke("FindRange", new System.Type[] {
typeof(string),
typeof(global::AxMicrosoft.Office.Interop.Owc11.AxSpreadsheet)}, args)));
return ret;
}
答案 0 :(得分:1)
我不熟悉OWC,所以我不能完全重写下面的代码,但下面是一些SpreadsheetGear代码,它将打开一个Excel文件并尝试在给定的工作表中找到一些关键字:
TCHAR szSep[8];
GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, szSep, 8);