C# 如何减少get#u range()参数中的范围,因为它不接受'-';(减)接线员? int nRows=2; int nColumns=dt.Rows.Count; 字符串upperLeftCell=“B2”; int endRowNumber=System.Int32.Parse(upperLeftCell.Substring(1))+nRows-1; char endColumnLetter=System.Convert.ToChar(Convert.ToInt32(upperLeftCell[0])+nColumns-1); string upperRightCell=System.string.Format(“{0}{1}”,endColumnLetter,System.Int32.Parse(upperLeftCell.Substring(1)); string lowerRightCell=System.string.Format(“{0}{1}”,endColumnLetter,endRowNumber); Excel.Range rg=ws.get_Range(upperLeftCell,lowerRightCell); 对于(int i=1;i

C# 如何减少get#u range()参数中的范围,因为它不接受'-';(减)接线员? int nRows=2; int nColumns=dt.Rows.Count; 字符串upperLeftCell=“B2”; int endRowNumber=System.Int32.Parse(upperLeftCell.Substring(1))+nRows-1; char endColumnLetter=System.Convert.ToChar(Convert.ToInt32(upperLeftCell[0])+nColumns-1); string upperRightCell=System.string.Format(“{0}{1}”,endColumnLetter,System.Int32.Parse(upperLeftCell.Substring(1)); string lowerRightCell=System.string.Format(“{0}{1}”,endColumnLetter,endRowNumber); Excel.Range rg=ws.get_Range(upperLeftCell,lowerRightCell); 对于(int i=1;i,c#,excel,range,C#,Excel,Range,您应该能够在创建字符串lowerRightCell时执行此操作 int nRows = 2; int nColumns = dt.Rows.Count; string upperLeftCell = "B2"; int endRowNumber = System.Int32.Parse(upperLeftCell.Substring(1))+ nRows - 1; char endColumnLetter = System.Convert.ToChar(Convert.ToInt32(upper

您应该能够在创建字符串lowerRightCell时执行此操作

int nRows = 2;
int nColumns = dt.Rows.Count;
string upperLeftCell = "B2";
int endRowNumber = System.Int32.Parse(upperLeftCell.Substring(1))+ nRows - 1;
char endColumnLetter = System.Convert.ToChar(Convert.ToInt32(upperLeftCell[0]) + nColumns - 1);
string upperRightCell = System.String.Format("{0}{1}",endColumnLetter, System.Int32.Parse(upperLeftCell.Substring(1)));
string lowerRightCell = System.String.Format("{0}{1}",endColumnLetter, endRowNumber);

Excel.Range rg = ws.get_Range(upperLeftCell, lowerRightCell);
for (int i = 1; i <= dt.Rows.Count; i++)
{
   rg[1, i] = dt.Rows[i - 1][0].ToString();      //For Adding Header Text
   rg[2, i] = int.Parse(dt.Rows[i - 1][1].ToString());  //For Adding Datarow Value
}

Excel.Range chartRange = ws.get_Range(upperLeftCell, lowerRightCell);
string lowerRightCell = System.String.Format("{0}{1}",endColumnLetter, endRowNumber - 1);