C# 如何在C语言中打印多个excel工作表上的数据
我有一个用于创建excel的C应用程序。代码如下所示:C# 如何在C语言中打印多个excel工作表上的数据,c#,html,excel,stringbuilder,file-writing,C#,Html,Excel,Stringbuilder,File Writing,我有一个用于创建excel的C应用程序。代码如下所示: public void CreateExcelSheet() { StringBuilder sbWriteBuffer = new StringBuilder(); sbWriteBuffer.Append("<html xmlns:x='urn:schemas-microsoft-com:office:excel'>"); sbWriteBuffer.Append("&
public void CreateExcelSheet()
{
StringBuilder sbWriteBuffer = new StringBuilder();
sbWriteBuffer.Append("<html xmlns:x='urn:schemas-microsoft-com:office:excel'>");
sbWriteBuffer.Append("<head>");
sbWriteBuffer.Append("<meta http-equiv='Content-Type' content='text/html;charset=windows-1252'>");
sbWriteBuffer.Append("<!--[if gte mso 9]>");
sbWriteBuffer.Append("<xml>");
sbWriteBuffer.Append("<x:ExcelWorkbook>");
sbWriteBuffer.Append("<x:ExcelWorksheets>");
sbWriteBuffer.Append("<x:ExcelWorksheet>");
sbWriteBuffer.Append("<x:Name>Sheet1</x:Name>");
sbWriteBuffer.Append("<x:WorksheetOptions>");
sbWriteBuffer.Append("<x:Panes>");
sbWriteBuffer.Append("</x:Panes>");
sbWriteBuffer.Append("</x:WorksheetOptions>");
sbWriteBuffer.Append("</x:ExcelWorksheet>");
sbWriteBuffer.Append("<x:ExcelWorksheet>");
sbWriteBuffer.Append("<x:Name>Sheet2</x:Name>");
sbWriteBuffer.Append("<x:WorksheetOptions>");
sbWriteBuffer.Append("<x:Panes>");
sbWriteBuffer.Append("</x:Panes>");
sbWriteBuffer.Append("</x:WorksheetOptions>");
sbWriteBuffer.Append("</x:ExcelWorksheet>");
sbWriteBuffer.Append("</x:ExcelWorksheets>");
sbWriteBuffer.Append("</x:ExcelWorkbook>");
sbWriteBuffer.Append("</xml>");
sbWriteBuffer.Append("<![endif]-->");
sbWriteBuffer.Append("</head>");
//*************Data shouldbe in worksheet 1
sbWriteBuffer.Append("<body>");
sbWriteBuffer.Append("<table>");
sbWriteBuffer.Append("<tr></tr>");
sbWriteBuffer.Append("<tr style='background-color:brown;border:solid;border-width:1px'>");
sbWriteBuffer.Append("<th>" + "Details of customers on 11/4/2014" + "</th>");
sbWriteBuffer.Append("</tr>");
sbWriteBuffer.Append("<tr><td>ID</td><td>Name</td><td>Balance</td></tr>");
sbWriteBuffer.Append("<tr><td>1234</td><td>Al Bundy</td><td>45</td></tr>");
sbWriteBuffer.Append("<tr><td>1234</td><td>Chris Mary</td><td>20</td></tr>");
sbWriteBuffer.Append("<tr></tr>");
sbWriteBuffer.Append("</table>");
sbWriteBuffer.Append("</body>");
//*************************************************
//*************Data shouldbe in worksheet 2
sbWriteBuffer.Append("<body>");
sbWriteBuffer.Append("<table>");
sbWriteBuffer.Append("<tr></tr>");
sbWriteBuffer.Append("<tr>");
sbWriteBuffer.Append("<tr style='background-color:brown;border:solid;border-width:1px'>");
sbWriteBuffer.Append("<th>" + "Details of customers on 11/3/2014" + "</th>");
sbWriteBuffer.Append("</tr>");
sbWriteBuffer.Append("<tr><td>ID</td><td>Name</td><td>Balance</td></tr>");
sbWriteBuffer.Append("<tr><td>9876</td><td>Homer Simpson</td><td>-129</td></tr>");
sbWriteBuffer.Append("<tr><td>5555</td><td>Peter Griffin</td><td>0</td></tr>");
sbWriteBuffer.Append("<tr></tr>");
sbWriteBuffer.Append("</table>");
sbWriteBuffer.Append("</body>");
//***************************************************
sbWriteBuffer.Append("</html>");
System.IO.File.WriteAllText(@"D:\excel.xls", sbWriteBuffer.ToString());
}
问题是我需要将数据打印在excel文件的两个工作表上。但是现在我发现它写在同一张工作表上。为了达到我的要求,我需要在代码中做什么修改?
如何在C语言中打印多个工作表上的数据
在上面相同的代码中,如何指定要在特定工作表中显示的一组数据?如何将工作表与上述代码中的表关联/连接?为什么不为此使用组件?ePlus非常简单且功能强大:
为什么不使用Microsoft.Office.Interop软件包?或者至少像在这个项目中那样构造数据,这样您就可以处理缓冲区中的概念而不是字符串