Operation for Excel with NPOI and Excel.Load
Posted jessicaxia
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Operation for Excel with NPOI and Excel.Load相关的知识,希望对你有一定的参考价值。
Main function to operate Excel.
1. Define a mapper class for Excel. eg:
class ExcelColMapper
{
[cloumn (index=10)]
public string basePathCol{get;set;}
[cloumn (index=11)]
public string extPathCol{get;set;}
[cloumn (index=13)]
public string verbCol{get;set;}
}
2. define a ExcelReader used to retrieve data from Excel
FileStream fStream;
string fileName;
Public ExcelReader(string filename)
{
filename=fileName;
//XSSFWorkbook abook;
using(FileStream file=new FileStream(filename,FileMode.Open,FileAccess.Read))
{
abook=new XSSFWorkbook(file);
try{
for(int row=1;row<=sheet.LastRowNum;row++)
{
List<EndPointExcelColMapper> results = new List<EndPointExcelColMapper>();
results.Add(new EndPointExcelColMapper()
{
jsonRequest=sheet.GetRow(row).GetCell(0).StringCellValue,
cdfResponse=sheet.GetRow(row).GetCell(2).StringCellValue,
jsonResponse=sheet.GetRow(row).GetCell(3).StringCellValue
}
Catch(Exception ex)
{
throw ex;
}
}
}
}
}
public List<EndPtCDFRespMapping> retrieveuriTOCDFobjMapping()
{
List<ExcelColMapper> result=.Load<ExcelColMapper>(filename,1,0).ToList();
List<EndPtCDFRespMapping> fullMapping = new List<EndPtCDFRespMapping>();
results.RemoveAll(s=>s.typeCol==null);
result.RemoveAll(s=>s.typpeCol.ToString()=="Request");
for(int n=0;n<results.count;n++)
{
string UriFromSwagger=UriTransform(result[n].basePathCol+result[n].extPathCol).Item1;
fullMapping.Add(new EndPtCDFResMapping(uriFromSwagger,result[n].verbCol,result[n].cdfNameSpaceCol+result[n].cdfObjCpl));
}
return fullMapping;
}
private Tuple<string,int> uriTransform(string fulluritemp)
{
string fulluri=fulluritemp.Substring(0,fulluritemp.Length-1);
string [email protected]"d{2,}|({[^0-9].*?})";
Regex regExp=new Regex(pattern);
string tempuri="";
int i=0;
string result=fulluri;
do
{
tempuri=result;
string replacement ="{"+i+"}";
result=regExp.Replace(result,replacement,1);
i++;
} while(!result.Equals(tempuri));
return new Tuple<string,int>(result,i-1)
}
以上是关于Operation for Excel with NPOI and Excel.Load的主要内容,如果未能解决你的问题,请参考以下文章
1381. Design a Stack With Increment Operation
Couldn't find log associated with operation handle: OperationHandle [opType=EXECUTE_STATEMENT, g
CXF: No binding operation info while invoking unknown method with params unknown.
c# mono raspberry pi GPIO with Raspberry#getting Operation is not valid
ACR1222L FF 82 Load Authentication Keys failed with 63 00 Operation Failed
ORA-27300: OS system dependent operation:sendmsg failed with status: 105 ORA-27301: OS failure messa