用c#获取excel表格内容,转换成html源代码输出,怎么判断和输出合并单元格?
excel = new Excel.Application();
                excel.UserControl = true;
                excel.DisplayAlerts = false;
                excel.Application.Workbooks.Open(fileName, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
                wbs = excel.Workbooks;
                wb = wbs[1];
                for (int k = 0; k < wb.Worksheets.Count; k++)
                {
                    ws = (Excel.Worksheet)wb.Worksheets[k + 1];
                    if (ws == null) continue;
                    int rowCount = ws.UsedRange.Rows.Count;
                    int colCount = ws.UsedRange.Columns.Count;
                    sb.AppendLine("<table width=\"100%\" cellpadding=0 cellspacing=0 border=1 bordercolor=\"#888888\" style=\"border-collapse:collapse;padding:4px;\">");
                    for (int i = 0; i < rowCount; i++)
                    {
                        sb.AppendLine("<tr>");
                        for (int j = 0; j < colCount; j++)
                        {
                            range1 = ws.Range[ws.Cells[i + 1, j + 1], ws.Cells[i + 1, j + 1]];
                            if (range1 != null)
                            {
                                if (range1.Text.ToString() == "")
                                {
                                    sb.AppendLine("<td></td>");
                                }
                                else
                                {
                                 sb.AppendLine("<td>" + range1.Text + "</td>");
                                }
                            }
                            else
                            {
                                sb.AppendLine("");
                            }
                        }
                        sb.AppendLine("</tr>");
                    }
                    sb.AppendLine("</table>");
                    sb.AppendLine("<br>");

如题

1个回答

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!