代码如下:
aspx页面:
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm4.aspx.vb" Inherits="WebApplication1.WebForm4" %>
<%@ Register Assembly="FarPoint.Web.SpreadJ" Namespace="FarPoint.Web.Spread" TagPrefix="FarPoint" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<FarPoint:FpSpread ID="FpSpread1" runat="server" BorderColor="#A0A0A0" BorderStyle="Solid" BorderWidth="1px" Height="300" Width="600">
<CommandBar BackColor="#F6F6F6" ButtonFaceColor="Control" ButtonHighlightColor="ControlLightLight" ButtonShadowColor="ControlDark"></CommandBar>
<Sheets>
<FarPoint:SheetView SheetName="Sheet1"></FarPoint:SheetView>
</Sheets>
</FarPoint:FpSpread>
<asp:Button ID="Button1" runat="server" Text="Sort" />
</div>
</form>
</body>
</html>
后台代码:
Imports FarPoint.Web.Spread
Public Class WebForm4
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not IsPostBack Then
FpSpread1.Sheets(0).RowCount = 6
FpSpread1.Sheets(0).Columns(0).Width = 150
FpSpread1.Sheets(0).Columns(2).Width = 200
FpSpread1.Sheets(0).Cells(0, 0).Value = 150
FpSpread1.Sheets(0).Cells(1, 0).Value = 510
FpSpread1.Sheets(0).Cells(2, 0).Value = 250
FpSpread1.Sheets(0).Cells(3, 0).Value = 50
FpSpread1.Sheets(0).Cells(4, 0).Value = 250
FpSpread1.Sheets(0).Cells(5, 0).Value = 290
FpSpread1.Sheets(0).AddRows(6, 1)
Dim Formula As String = "SUM(A1:A2)"
FpSpread1.Sheets(0).Cells(6, 0).Formula = Formula
FpSpread1.Sheets(0).Rows(6).BackColor = System.Drawing.Color.LightSkyBlue
FpSpread1.Sheets(0).SetText(6, 2, "第1-2行合计")
End If
End Sub
Protected Sub Button1_Click(sender As Object, e As EventArgs)
FpSpread1.ActiveSheetView.AllowSort = True
' 排序做成
Dim sinfo As FarPoint.Web.Spread.SortInfo() = New FarPoint.Web.Spread.SortInfo(0) {}
sinfo(0) = New SortInfo(0, True)
FpSpread1.ActiveSheetView.SortRows(0, FpSpread1.ActiveSheetView.RowCount - 1, sinfo)
End Sub
End Class
画面效果:第七行单元格内容是"SUM(A1:A2)"
Sort按钮按下:第七行单元格内容没有变化
|