sinat_30056991 2015-08-28 08:15 采纳率: 61.5%
浏览 2542
已采纳

用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条回答 默认 最新

  • threenewbee 2015-08-29 15:03
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?