我怎样才能在 asp.net c# 3.5 中实现这种 excel 格式
how can i achieve this excel format in asp.net c# 3.5
报告 Abc- 示例
Excel 格式 2007
(我必须达到以下格式)
Job Number : 123________ Job Date : ___________ Destination : ________
_________________________________________________________________________________
Voucher No. | Voucher Date | Expence | Income
_________________________________________________________________________________
100 | 21/May/2021 | 100 | 50
101 | 20/may/2020 | 200 | 100
_________________________________________________________________________________
Gross Profit : -150 Total | 300 | 150
_________________________________________________________________________________
_________________________________________________________________________________
Job Number : 124________ Job Date : ___________ Destination : ________
_________________________________________________________________________________
Voucher No. | Voucher Date | Expence | Income
_________________________________________________________________________________
105 | 21/May/2021 | 100 | 500
109 | 20/may/2020 | 500 | 500
_________________________________________________________________________________
Gross Profit : 400 Total | 600 | 1000
此工号及凭证号显示多次(N)次……
这是我的数据表来自数据库...(原始数据)
JobNo | JobDate | Destination | VoucherNo | Voucher Date | Expence | Income
--------------------------------------------------------------------------------------------
123 | India | 100 | 21/May/2021 | 100 | 50
123 | India | 101 | 20/may/2020 | 200 | 100
124 | Canada | 105 | 21/May/2021 | 100 | 500
124 | Canada | 109 | 20/may/2020 | 500 | 500
---------------------------------------------------------------------------------------------
我试过了...我可以更改数据表...如下所示
JobNo | JobDate | Destination | VoucherNo | Voucher Date | Expence | Income
--------------------------------------------------------------------------------------------
123 | India | 100 | 21/May/2021 | 100 | 50
123 | India | 101 | 20/may/2020 | 200 | 100
------------------------------------------------------------------------------------------------
Gross Profit: -150 300 600
----------------------------------------------------------------------------------------------
124 | Canada | 105 | 21/May/2021 | 100 | 500
124 | Canada | 109 | 20/may/2020 | 500 | 500
---------------------------------------------------------------------------------------------
Gross Profit: 400 | 600 | 1000
---------------------------------------------------------------------------------------------
我已将数据导出为以下格式......
Report ABC From ABC Date to XYZ Date
JobNo | JobDate | Destination | VoucherNo | Voucher Date | Expence | Income
--------------------------------------------------------------------------------------------
123 | India | 100 | 21/May/2021 | 100 | 50
| | 101 | 20/may/2020 | 200 | 100
------------------------------------------------------------------------------------------------
Gross Profit: -150 300 600
----------------------------------------------------------------------------------------------
124 | Canada | 105 | 21/May/2021 | 100 | 500
| | 109 | 20/may/2020 | 500 | 500
---------------------------------------------------------------------------------------------
Gross Profit: 400 | 600 | 1000
---------------------------------------------------------------------------------------------
But I want to acheive this ..
Job Number : 123________ Job Date : ___________ Destination : ________
_________________________________________________________________________________
Voucher No. | Voucher Date | Expence | Income
_________________________________________________________________________________
100 | 21/May/2021 | 100 | 50
101 | 20/may/2020 | 200 | 100
_________________________________________________________________________________
Gross Profit : -150 Total | 300 | 150
_________________________________________________________________________________
_________________________________________________________________________________
Job Number : 124________ Job Date : ___________ Destination : ________
_________________________________________________________________________________
Voucher No. | Voucher Date | Expence | Income
_________________________________________________________________________________
105 | 21/May/2021 | 100 | 500
109 | 20/may/2020 | 500 | 500
_________________________________________________________________________________
Gross Profit : 400 Total | 600 | 1000
This Job Number and Voucher No. Shows multiple(N) time......
I'm Getting Data From Sql Server as Database..
I have using asp.net 3.5 framework...please don't suggest any ddl..i
have not right add any ddl file add at client Side....
How can i achieve this ...any help will be appreciated....Thank U!!
好的,这是解决问题的方法之一!
首先,您有一些数据并不是真正的列,然后在其中,您需要一个数据网格。
因此,我们只需按 JobNo 对数据进行分组。
因为这不是真正的列,而是一些文本数据,所以转发器控件就是完成该任务的工作。
现在,在中继器内部,我们需要 table/grid 之类的东西。所以在转发器控件中,我们放入一个 gridview。
因此,我们的标记将如下所示:
<div style="width:38%">
<br />
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<asp:Label runat="server" Text="Job Number:"></asp:Label>
<asp:TextBox ID="txtJobNum" runat="server" Text='<%# Eval("JobNo") %>'></asp:TextBox>
<asp:Label ID="Label1" runat="server" Text="Job Date; _____________" Style="margin-left:20px"></asp:Label>
<asp:Label ID="Label2" runat="server" Text="Job Destination _____________" Style="margin-left:20px"></asp:Label>
<br />
<br />
<asp:GridView ID="GridView1" runat="server" ShowFooter="true"></asp:GridView>
<hr />
<br />
</ItemTemplate>
</asp:Repeater>
<br />
</div>
所以 repater 是我们的“标题区域”,里面有网格。
因此,在页面加载时,我们填充转发器,并且对于每个转发器行事件,我们填充网格。
因此代码如下所示:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If IsPostBack = False Then
Using cmdSQL As New SqlCommand("SELECT JobNo FROM jobs GROUP BY JobNo",
New SqlConnection(My.Settings.TEST4))
cmdSQL.Connection.Open()
Repeater1.DataSource = cmdSQL.ExecuteReader
Repeater1.DataBind()
End Using
End If
End Sub
Protected Sub Repeater1_ItemDataBound(sender As Object, e As RepeaterItemEventArgs) Handles Repeater1.ItemDataBound
Dim txtJobNum As TextBox = e.Item.FindControl("txtJobNum")
Dim gv As GridView = e.Item.FindControl("GridView1")
Using cmdSQL As New SqlCommand("Select * from jobs where JobNo = " & txtJobNum.Text, New SqlConnection(My.Settings.TEST4))
cmdSQL.Connection.Open()
Dim MyTable As New DataTable
MyTable.Load(cmdSQL.ExecuteReader)
gv.DataSource = MyTable
gv.DataBind()
' now add total row
Dim Expense As Decimal = 0
Dim Income As Decimal = 0
For Each OneRow In MyTable.Rows
Expense += OneRow("Expense")
Income += OneRow("Income")
Next
Dim Profit As Decimal = Income - Expense
Dim ix As Integer = gv.FooterRow.Cells.Count
gv.FooterRow.Cells(1).Text = "Gross Profit ="
gv.FooterRow.Cells(2).Text = Profit
gv.FooterRow.Cells(ix - 2).Text = Expense
gv.FooterRow.Cells(ix - 1).Text = Income
End Using
End Sub
编辑:- 此 post 未标记为 C# - 所以我 post 编辑为 vb。
但是,作为 c#,代码将如下所示:
protected void Page_Load(object sender, System.EventArgs e)
{
if (IsPostBack == false)
{
using (SqlCommand cmdSQL = new SqlCommand("SELECT JobNo FROM jobs GROUP BY JobNo", new SqlConnection(My.Settings.TEST4)))
{
cmdSQL.Connection.Open();
Repeater1.DataSource = cmdSQL.ExecuteReader;
Repeater1.DataBind();
}
}
}
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
TextBox txtJobNum = e.Item.FindControl("txtJobNum");
GridView gv = e.Item.FindControl("GridView1");
using (SqlCommand cmdSQL = new SqlCommand("Select * from jobs where JobNo = " + txtJobNum.Text, new SqlConnection(My.Settings.TEST4)))
{
cmdSQL.Connection.Open();
DataTable MyTable = new DataTable();
MyTable.Load(cmdSQL.ExecuteReader);
gv.DataSource = MyTable;
gv.DataBind();
// now add total row
decimal Expense = 0;
decimal Income = 0;
foreach (var OneRow in MyTable.Rows)
{
Expense += OneRow("Expense");
Income += OneRow("Income");
}
decimal Profit = Income - Expense;
int ix = gv.FooterRow.Cells.Count;
gv.FooterRow.Cells(1).Text = "Gross Profit =";
gv.FooterRow.Cells(2).Text = Profit;
gv.FooterRow.Cells(ix - 2).Text = Expense;
gv.FooterRow.Cells(ix - 1).Text = Income;
}
}
输出如下所示:
现在在上面,我只有 table 中的数据。不清楚 how/where/when/what 您的数据正在被导入。但是得到的数据变成了一个数据table。如果你只有一个 table,并且不能使用 SQL group by,那么只需制作第二个 table,并将 JobNo 循环到那个 table,然后绑定到中继器。
这里的方法、概念、想法?
您的标题部分和文本是转发器控件 - 因为它不是真正的 table。
那么网格part/table?那可以是网格视图。您为每个组行填写它,然后当然会汇总结果并将其推入基础行。
报告 Abc- 示例
Excel 格式 2007 (我必须达到以下格式)
Job Number : 123________ Job Date : ___________ Destination : ________
_________________________________________________________________________________
Voucher No. | Voucher Date | Expence | Income
_________________________________________________________________________________
100 | 21/May/2021 | 100 | 50
101 | 20/may/2020 | 200 | 100
_________________________________________________________________________________
Gross Profit : -150 Total | 300 | 150
_________________________________________________________________________________
_________________________________________________________________________________
Job Number : 124________ Job Date : ___________ Destination : ________
_________________________________________________________________________________
Voucher No. | Voucher Date | Expence | Income
_________________________________________________________________________________
105 | 21/May/2021 | 100 | 500
109 | 20/may/2020 | 500 | 500
_________________________________________________________________________________
Gross Profit : 400 Total | 600 | 1000
此工号及凭证号显示多次(N)次…… 这是我的数据表来自数据库...(原始数据)
JobNo | JobDate | Destination | VoucherNo | Voucher Date | Expence | Income
--------------------------------------------------------------------------------------------
123 | India | 100 | 21/May/2021 | 100 | 50
123 | India | 101 | 20/may/2020 | 200 | 100
124 | Canada | 105 | 21/May/2021 | 100 | 500
124 | Canada | 109 | 20/may/2020 | 500 | 500
---------------------------------------------------------------------------------------------
我试过了...我可以更改数据表...如下所示
JobNo | JobDate | Destination | VoucherNo | Voucher Date | Expence | Income
--------------------------------------------------------------------------------------------
123 | India | 100 | 21/May/2021 | 100 | 50
123 | India | 101 | 20/may/2020 | 200 | 100
------------------------------------------------------------------------------------------------
Gross Profit: -150 300 600
----------------------------------------------------------------------------------------------
124 | Canada | 105 | 21/May/2021 | 100 | 500
124 | Canada | 109 | 20/may/2020 | 500 | 500
---------------------------------------------------------------------------------------------
Gross Profit: 400 | 600 | 1000
---------------------------------------------------------------------------------------------
我已将数据导出为以下格式......
Report ABC From ABC Date to XYZ Date
JobNo | JobDate | Destination | VoucherNo | Voucher Date | Expence | Income
--------------------------------------------------------------------------------------------
123 | India | 100 | 21/May/2021 | 100 | 50
| | 101 | 20/may/2020 | 200 | 100
------------------------------------------------------------------------------------------------
Gross Profit: -150 300 600
----------------------------------------------------------------------------------------------
124 | Canada | 105 | 21/May/2021 | 100 | 500
| | 109 | 20/may/2020 | 500 | 500
---------------------------------------------------------------------------------------------
Gross Profit: 400 | 600 | 1000
---------------------------------------------------------------------------------------------
But I want to acheive this ..
Job Number : 123________ Job Date : ___________ Destination : ________
_________________________________________________________________________________
Voucher No. | Voucher Date | Expence | Income
_________________________________________________________________________________
100 | 21/May/2021 | 100 | 50
101 | 20/may/2020 | 200 | 100
_________________________________________________________________________________
Gross Profit : -150 Total | 300 | 150
_________________________________________________________________________________
_________________________________________________________________________________
Job Number : 124________ Job Date : ___________ Destination : ________
_________________________________________________________________________________
Voucher No. | Voucher Date | Expence | Income
_________________________________________________________________________________
105 | 21/May/2021 | 100 | 500
109 | 20/may/2020 | 500 | 500
_________________________________________________________________________________
Gross Profit : 400 Total | 600 | 1000
This Job Number and Voucher No. Shows multiple(N) time......
I'm Getting Data From Sql Server as Database..
I have using asp.net 3.5 framework...please don't suggest any ddl..i have not right add any ddl file add at client Side....
How can i achieve this ...any help will be appreciated....Thank U!!
好的,这是解决问题的方法之一!
首先,您有一些数据并不是真正的列,然后在其中,您需要一个数据网格。
因此,我们只需按 JobNo 对数据进行分组。
因为这不是真正的列,而是一些文本数据,所以转发器控件就是完成该任务的工作。
现在,在中继器内部,我们需要 table/grid 之类的东西。所以在转发器控件中,我们放入一个 gridview。
因此,我们的标记将如下所示:
<div style="width:38%">
<br />
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<asp:Label runat="server" Text="Job Number:"></asp:Label>
<asp:TextBox ID="txtJobNum" runat="server" Text='<%# Eval("JobNo") %>'></asp:TextBox>
<asp:Label ID="Label1" runat="server" Text="Job Date; _____________" Style="margin-left:20px"></asp:Label>
<asp:Label ID="Label2" runat="server" Text="Job Destination _____________" Style="margin-left:20px"></asp:Label>
<br />
<br />
<asp:GridView ID="GridView1" runat="server" ShowFooter="true"></asp:GridView>
<hr />
<br />
</ItemTemplate>
</asp:Repeater>
<br />
</div>
所以 repater 是我们的“标题区域”,里面有网格。
因此,在页面加载时,我们填充转发器,并且对于每个转发器行事件,我们填充网格。
因此代码如下所示:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If IsPostBack = False Then
Using cmdSQL As New SqlCommand("SELECT JobNo FROM jobs GROUP BY JobNo",
New SqlConnection(My.Settings.TEST4))
cmdSQL.Connection.Open()
Repeater1.DataSource = cmdSQL.ExecuteReader
Repeater1.DataBind()
End Using
End If
End Sub
Protected Sub Repeater1_ItemDataBound(sender As Object, e As RepeaterItemEventArgs) Handles Repeater1.ItemDataBound
Dim txtJobNum As TextBox = e.Item.FindControl("txtJobNum")
Dim gv As GridView = e.Item.FindControl("GridView1")
Using cmdSQL As New SqlCommand("Select * from jobs where JobNo = " & txtJobNum.Text, New SqlConnection(My.Settings.TEST4))
cmdSQL.Connection.Open()
Dim MyTable As New DataTable
MyTable.Load(cmdSQL.ExecuteReader)
gv.DataSource = MyTable
gv.DataBind()
' now add total row
Dim Expense As Decimal = 0
Dim Income As Decimal = 0
For Each OneRow In MyTable.Rows
Expense += OneRow("Expense")
Income += OneRow("Income")
Next
Dim Profit As Decimal = Income - Expense
Dim ix As Integer = gv.FooterRow.Cells.Count
gv.FooterRow.Cells(1).Text = "Gross Profit ="
gv.FooterRow.Cells(2).Text = Profit
gv.FooterRow.Cells(ix - 2).Text = Expense
gv.FooterRow.Cells(ix - 1).Text = Income
End Using
End Sub
编辑:- 此 post 未标记为 C# - 所以我 post 编辑为 vb。
但是,作为 c#,代码将如下所示:
protected void Page_Load(object sender, System.EventArgs e)
{
if (IsPostBack == false)
{
using (SqlCommand cmdSQL = new SqlCommand("SELECT JobNo FROM jobs GROUP BY JobNo", new SqlConnection(My.Settings.TEST4)))
{
cmdSQL.Connection.Open();
Repeater1.DataSource = cmdSQL.ExecuteReader;
Repeater1.DataBind();
}
}
}
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
TextBox txtJobNum = e.Item.FindControl("txtJobNum");
GridView gv = e.Item.FindControl("GridView1");
using (SqlCommand cmdSQL = new SqlCommand("Select * from jobs where JobNo = " + txtJobNum.Text, new SqlConnection(My.Settings.TEST4)))
{
cmdSQL.Connection.Open();
DataTable MyTable = new DataTable();
MyTable.Load(cmdSQL.ExecuteReader);
gv.DataSource = MyTable;
gv.DataBind();
// now add total row
decimal Expense = 0;
decimal Income = 0;
foreach (var OneRow in MyTable.Rows)
{
Expense += OneRow("Expense");
Income += OneRow("Income");
}
decimal Profit = Income - Expense;
int ix = gv.FooterRow.Cells.Count;
gv.FooterRow.Cells(1).Text = "Gross Profit =";
gv.FooterRow.Cells(2).Text = Profit;
gv.FooterRow.Cells(ix - 2).Text = Expense;
gv.FooterRow.Cells(ix - 1).Text = Income;
}
}
输出如下所示:
现在在上面,我只有 table 中的数据。不清楚 how/where/when/what 您的数据正在被导入。但是得到的数据变成了一个数据table。如果你只有一个 table,并且不能使用 SQL group by,那么只需制作第二个 table,并将 JobNo 循环到那个 table,然后绑定到中继器。
这里的方法、概念、想法?
您的标题部分和文本是转发器控件 - 因为它不是真正的 table。
那么网格part/table?那可以是网格视图。您为每个组行填写它,然后当然会汇总结果并将其推入基础行。