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
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题