HTML 표를 CSV 파일로 구문 분석하지만 원하는 수의 colspan 및 rowpspan을 유지하려고합니다.HTML 표를 CSV 파일 (colspan 및 rowspan)로 구문 분석
나는 을 사용하고 있습니다. ";" 구분 기호 셀입니다. 따라서, 예를 들어 2 개 열의 컬럼 스팬이있을 때 ";"는 2를 갖습니다.
tr 인디케이터가 끝나는 곳에서 테이블 내용을 추출하고 줄 바꿈을 할 수 있습니다. 하지만 치료 방법을 모르겠다 colspan 및 rowspan.
HtmlNodeCollection rows = tables[0].SelectNodes("tr");
// Aux vars
int i;
// ncolspan
// For each row...
for (i = 0; i < rows.Count; ++i)
{
// For each cell in the col...
foreach (HtmlNode cell in rows[i].SelectNodes("th|td"))
{
/* Unsuccessful attempt to treat colspan
foreach (HtmlNode n_cell in rows[i].SelectNodes("//td[@colspan]"))
{
ncolspan = n_cell.Attributes["colspan"].Value;
}
*/
text.Write(System.Text.RegularExpressions.Regex.Replace(cell.InnerText, @"\s\s+", ""));
text.Write(";");
/*
for (int x = 0; x <= int.Parse(ncolspan); x++)
{
text.Write(";");
}
*/
}
text.WriteLine();
ncolspan = "0";
}
도움이 필요하십니까? 고맙습니다!
UPDATE : 여기 간단한 예제 테이블 사용하기 :
<table id="T123" border="1">
<tr>
<td colspan="3"><center><font color="red">Title</font></center></td>
</tr>
<tr>
<th>R1 C1</th>
<th>R1 C2</th>
<th>R1 C3</th>
</tr>
<tr>
<td>R2 C1</td>
<td>R2 C2</td>
<td>R2 C3</td>
</tr>
<tr>
<td colspan="2">R3 C1 e C2 with "</td>
<td>R3 C3</td>
</tr>
<tr>
<td>R4 C1</td>
<td colspan=2>R4 C2 e C3 without "</td>
</tr>
<tr>
<td>R5 C1</td>
<td>R5 C2</td>
<td>R5 C3</td>
</tr>
<tr>
<td rowspan ="2">R6/R7 C1: Two lines rowspan. Must leave the second line blank.</td>
<td>R6 C2</td>
<td>R6 C3</td>
</tr>
<tr>
<td>R7 C2</td>
<td>R7 C3</td>
</tr>
<tr>
<td>End</td>
</tr>
</table>