C# 如何使用c跳过excel中跨多行的单元格#
我有一个for循环,它是这样的C# 如何使用c跳过excel中跨多行的单元格#,c#,excel,loops,C#,Excel,Loops,我有一个for循环,它是这样的 for (int i = 12; i < 200; i++) { //Console.WriteLine(Convert.ToString(sheet01.Cells[12, 2].Value2)); if (!(string.IsNullOrEmpty(sheet01.Cells[i, 2].Value2)) && sheet01.Cells[i, 2].Value2.Length == 4) { C
for (int i = 12; i < 200; i++)
{
//Console.WriteLine(Convert.ToString(sheet01.Cells[12, 2].Value2));
if (!(string.IsNullOrEmpty(sheet01.Cells[i, 2].Value2)) && sheet01.Cells[i, 2].Value2.Length == 4)
{
Console.WriteLine(sheet01.Name);
hcnNumber.Add(Convert.ToString(sheet01.Cells[i, 2].Value2));
}
}
for(int i=12;i<200;i++)
{
//Console.WriteLine(Convert.ToString(sheet01.Cells[12,2].Value2));
if(!(string.IsNullOrEmpty(sheet01.Cells[i,2].Value2))&&sheet01.Cells[i,2].Value2.Length==4)
{
Console.WriteLine(表01.名称);
hcnNumber.Add(Convert.ToString(sheet01.Cells[i,2].Value2));
}
}
每当单元格[i,2]跨越多个列时,此代码就会遇到错误
如何跳过跨越多个列的行
因此,如果row.length>1
谢谢我尝试在本地系统上满足您的要求。如果我理解您的要求,您只需要显示只有第1列有值的行,例如,如果一行有10列,其中所有或多个列都包含数据,则需要跳过该行。我认为这会对你实现目标有所帮助。 下面是循环使用并给出预期结果的代码
Excel.Application xlApp = new Excel.Application();
Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(@"C:\Users\acn\Desktop\CopyofFinancialSample.xlsx");
Excel._Worksheet xlWorksheet = xlWorkbook.Sheets[1];
Excel.Range xlRange = xlWorksheet.UsedRange;
int rowCount = xlRange.Rows.Count;
int colCount = xlRange.Columns.Count;
for (int i = 1; i <= rowCount; i++)
{
int count = 0;
for (int j = 1; j <= colCount; j++)
{
//add useful things here!
if (j != 1)
{
if (xlRange.Cells[i, j] != null && xlRange.Cells[i, j].Value2 != null)
{
count++;
}
}
}
if (count > 0)
{
}
else
{
if (xlRange.Cells[i, 1] != null && xlRange.Cells[i, 1].Value2 != null)
Console.WriteLine(xlRange.Cells[i, 1].Value2.ToString() + "\t");
}
}
Excel.Application xlApp=新建Excel.Application();
Excel.Workbook xlWorkbook=xlApp.Workbooks.Open(@“C:\Users\acn\Desktop\CopyofFinancialSample.xlsx”);
Excel._工作表xlWorksheet=xlWorkbook.Sheets[1];
Excel.Range xlRange=xlWorksheet.UsedRange;
int rowCount=xlRange.Rows.Count;
int colCount=xlRange.Columns.Count;
对于(int i=1;i我尝试在我的本地系统上处理您的需求。如果我了解您的需求,您只需要显示只有第1列有值的行,例如,如果一行有10列,其中所有或多个列都包含数据,则需要跳过。我认为这应该有助于您实现目标。
下面是循环使用并给出预期结果的代码
Excel.Application xlApp = new Excel.Application();
Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(@"C:\Users\acn\Desktop\CopyofFinancialSample.xlsx");
Excel._Worksheet xlWorksheet = xlWorkbook.Sheets[1];
Excel.Range xlRange = xlWorksheet.UsedRange;
int rowCount = xlRange.Rows.Count;
int colCount = xlRange.Columns.Count;
for (int i = 1; i <= rowCount; i++)
{
int count = 0;
for (int j = 1; j <= colCount; j++)
{
//add useful things here!
if (j != 1)
{
if (xlRange.Cells[i, j] != null && xlRange.Cells[i, j].Value2 != null)
{
count++;
}
}
}
if (count > 0)
{
}
else
{
if (xlRange.Cells[i, 1] != null && xlRange.Cells[i, 1].Value2 != null)
Console.WriteLine(xlRange.Cells[i, 1].Value2.ToString() + "\t");
}
}
Excel.Application xlApp=新建Excel.Application();
Excel.Workbook xlWorkbook=xlApp.Workbooks.Open(@“C:\Users\acn\Desktop\CopyofFinancialSample.xlsx”);
Excel._工作表xlWorksheet=xlWorkbook.Sheets[1];
Excel.Range xlRange=xlWorksheet.UsedRange;
int rowCount=xlRange.Rows.Count;
int colCount=xlRange.Columns.Count;
对于(int i=1;我在网上找不到与此问题类似的内容。我正在寻找一个if语句,该语句可以检测单元格编号是否跨越>1行。我在网上找不到与此问题类似的内容。我正在寻找一个if语句,该语句可以检测单元格编号是否跨越>1行。