フォント
フォント情報を任意に変更することが可能です。
背景色などと同様、セル単位、列単位、行単位など様々な単位で設定することが可能です。
このサンプルではフォント名・斜体・太字・アンダーライン・取り消し線を全セルに適用します。
| ID | 氏名 | カナ | 生年月日 | 性別 | 血液型 | 部署 | 入社日 | メールアドレス |
1 | 1001 | 亀甲 滋万 | キコウ シゲマ | 1950/02/04 | 男 | A | 人事部 | 1972/04/01 | sigema_kikou@abc.co.jp |
2 | 1002 | 寒田 希世 | カンダ キヨ | 1959/06/28 | 女 | B | 人事部 | 1981/04/01 | kiyo_kanda@bbb.or.jp |
3 | 1003 | 小和瀬 澄 | オワセ キヨ | 1969/03/06 | 男 | A | 人事部 | 1991/04/01 | kiyo_owase@aaa.co.jp |
4 | 1004 | 宇夫 早余子 | ウブ サヨコ | 1976/07/28 | 女 | O | 人事部 | 1998/04/01 | sayoko_ubu@bbb.or.jp |
5 | 1005 | 宇田津 聖智 | ウダツ キヨトモ | 1965/09/04 | 男 | A | 営業部 | 1987/04/01 | kiyotomo_udatu@abc.co.jp |
6 | 1006 | 茨城 昭児 | イバラキ ショウジ | 1963/04/28 | 男 | O | 営業部 | 1985/04/01 | shouzi_ibaraki@xyz.ne.jp |
7 | 1007 | 石ヶ休 椎茄 | イシガキュウ シイナ | 1953/02/21 | 男 | O | 営業部 | 1975/04/01 | siina_isigagyuu@abc.co.jp |
8 | 1008 | 赤司 恵治郎 | アカツカサ ケイジロウ | 1968/08/02 | 男 | O | 経理部 | 1990/04/01 | keizirou_akatukasa@abc.co.jp |
9 | 1009 | 小橋 仰一 | オハシ ギョウイチ | 1972/03/02 | 男 | B | 経理部 | 1994/04/01 | gyouiti_ohasi@abc.co.jp |
10 | 1010 | 一重 公大 | イチジュウ コウダイ | 1964/04/19 | 男 | B | 経理部 | 1986/04/01 | koudai_itizyuu@xyz.ne.jp |
11 | 1011 | 稲並 勝五郎 | イナミ ショウゴロウ | 1962/02/18 | 男 | A | 営業部 | 1984/04/01 | shougorou_inami@bbb.or.jp |
12 | 1012 | 穎原 紀代一 | エイハラ キヨカズ | 1965/02/13 | 男 | O | 営業部 | 1987/04/01 | kiyokazu_eihara@bbb.or.jp |
|
ソースコード
別ウィンドウで表示
using System;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Configuration;
public partial class font : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack) return;
// データ連結
DataSet ds = new DataSet();
ds.ReadXml(MapPath("../App_Data/data.xml"));
FpSpread1.DataSource = ds;
// SPREAD初期化
InitSpread(FpSpread1.Sheets[0]);
// クライアント側スクリプトの設定
string clientScript = "<script language=\"JavaScript\">";
clientScript += "function SetFontName(fname)";
clientScript += "{";
clientScript += "var spread = document.getElementById(\"" + FpSpread1.ClientID + "\");";
clientScript += "spread.CallBack(\"SetFontName.\"+fname);";
clientScript += "}";
clientScript += "function SetFontItalic(fitalic)";
clientScript += "{";
clientScript += "var spread = document.getElementById(\"" + FpSpread1.ClientID + "\");";
clientScript += "spread.CallBack(\"SetFontItalic.\"+fitalic);";
clientScript += "}";
clientScript += "function SetFontBold(fbold)";
clientScript += "{";
clientScript += "var spread = document.getElementById(\"" + FpSpread1.ClientID + "\");";
clientScript += "spread.CallBack(\"SetFontBold.\"+fbold);";
clientScript += "}";
clientScript += "function SetUnderline(funderline)";
clientScript += "{";
clientScript += "var spread = document.getElementById(\"" + FpSpread1.ClientID + "\");";
clientScript += "spread.CallBack(\"SetUnderline.\"+funderline);";
clientScript += "}";
clientScript += "function SetStrikeout(fstrikeoute)";
clientScript += "{";
clientScript += "var spread = document.getElementById(\"" + FpSpread1.ClientID + "\");";
clientScript += "spread.CallBack(\"SetStrikeout.\"+fstrikeoute);";
clientScript += "}";
clientScript += "function SetForeColor(fcolor)";
clientScript += "{";
clientScript += "var spread = document.getElementById(\"" + FpSpread1.ClientID + "\");";
clientScript += "spread.CallBack(\"SetForeColor.\"+fcolor);";
clientScript += "}";
clientScript += "</script>";
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "fontScript", clientScript, false);
}
private void InitSpread(FarPoint.Web.Spread.SheetView sheet)
{
// SPREAD設定
FpSpread1.CommandBar.Visible = false;
FpSpread1.CssClass = "spreadStyle";
FpSpread1.UseClipboard = false;
// フォントサイズの設定
sheet.DefaultStyle.Font.Size = FontUnit.Parse("80%");
sheet.ColumnHeader.DefaultStyle.Font.Size = FontUnit.Parse("80%");
sheet.RowHeader.DefaultStyle.Font.Size = FontUnit.Parse("80%");
sheet.SheetCorner.DefaultStyle.Font.Size = FontUnit.Parse("80%");
// シート設定
sheet.PageSize = sheet.RowCount;
// 列幅の設定
sheet.Columns[0].Width = 36;
sheet.Columns[1].Width = 100;
sheet.Columns[2].Width = 100;
sheet.Columns[3].Width = 80;
sheet.Columns[4].Width = 36;
sheet.Columns[5].Width = 46;
sheet.Columns[6].Width = 49;
sheet.Columns[7].Width = 80;
sheet.Columns[8].Width = 181;
// 縦方向の揃え位置を中央に設定
sheet.DefaultStyle.VerticalAlign = VerticalAlign.Middle;
// 文字色の設定
sheet.DefaultStyle.ForeColor = System.Drawing.Color.Black;
}
protected void FpSpread1_ButtonCommand(object sender, FarPoint.Web.Spread.SpreadCommandEventArgs e)
{
if (e.CommandName.StartsWith("SetFontName"))
{
string[] strCom = e.CommandName.Split('.');
FpSpread1.ActiveSheetView.DefaultStyle.Font.Name = strCom[1];
}
else if (e.CommandName.StartsWith("SetFontItalic"))
{
string[] strCom = e.CommandName.Split('.');
FpSpread1.ActiveSheetView.DefaultStyle.Font.Italic = Convert.ToBoolean(strCom[1]);
}
else if (e.CommandName.StartsWith("SetFontBold"))
{
string[] strCom = e.CommandName.Split('.');
FpSpread1.ActiveSheetView.DefaultStyle.Font.Bold = Convert.ToBoolean(strCom[1]);
}
else if (e.CommandName.StartsWith("SetUnderline"))
{
string[] strCom = e.CommandName.Split('.');
FpSpread1.ActiveSheetView.DefaultStyle.Font.Underline = Convert.ToBoolean(strCom[1]);
}
else if (e.CommandName.StartsWith("SetStrikeout"))
{
string[] strCom = e.CommandName.Split('.');
FpSpread1.ActiveSheetView.DefaultStyle.Font.Strikeout = Convert.ToBoolean(strCom[1]);
}
else if (e.CommandName.StartsWith("SetForeColor"))
{
string[] strCom = e.CommandName.Split('.');
System.Drawing.Color bc = System.Drawing.Color.FromName(strCom[1]);
FpSpread1.ActiveSheetView.DefaultStyle.ForeColor = bc;
}
}
}
|
Partial Public Class font
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If IsPostBack Then
Return
End If
' データ連結
Dim ds As New System.Data.DataSet()
ds.ReadXml(MapPath("../App_Data/data.xml"))
FpSpread1.DataSource = ds
' SPREAD初期化
InitSpread(FpSpread1.Sheets(0))
' クライアント側スクリプトの設定
Dim clientScript As String = "<script language=""JavaScript"">"
clientScript += "function SetFontName(fname)"
clientScript += "{"
clientScript += "var spread = document.getElementById(""" + FpSpread1.ClientID & """);"
clientScript += "spread.CallBack(""SetFontName.""+fname);"
clientScript += "}"
clientScript += "function SetFontItalic(fitalic)"
clientScript += "{"
clientScript += "var spread = document.getElementById(""" + FpSpread1.ClientID & """);"
clientScript += "spread.CallBack(""SetFontItalic.""+fitalic);"
clientScript += "}"
clientScript += "function SetFontBold(fbold)"
clientScript += "{"
clientScript += "var spread = document.getElementById(""" + FpSpread1.ClientID & """);"
clientScript += "spread.CallBack(""SetFontBold.""+fbold);"
clientScript += "}"
clientScript += "function SetUnderline(funderline)"
clientScript += "{"
clientScript += "var spread = document.getElementById(""" + FpSpread1.ClientID & """);"
clientScript += "spread.CallBack(""SetUnderline.""+funderline);"
clientScript += "}"
clientScript += "function SetStrikeout(fstrikeoute)"
clientScript += "{"
clientScript += "var spread = document.getElementById(""" + FpSpread1.ClientID & """);"
clientScript += "spread.CallBack(""SetStrikeout.""+fstrikeoute);"
clientScript += "}"
clientScript += "function SetForeColor(fcolor)"
clientScript += "{"
clientScript += "var spread = document.getElementById(""" + FpSpread1.ClientID & """);"
clientScript += "spread.CallBack(""SetForeColor.""+fcolor);"
clientScript += "}"
clientScript += "</script>"
ScriptManager.RegisterClientScriptBlock(Me, Me.GetType(), "fontScript", clientScript, False)
End Sub
Private Sub InitSpread(ByVal sheet As FarPoint.Web.Spread.SheetView)
' SPREAD設定
FpSpread1.CommandBar.Visible = False
FpSpread1.CssClass = "spreadStyle"
FpSpread1.UseClipboard = False
' フォントサイズの設定
sheet.DefaultStyle.Font.Size = FontUnit.Parse("80%")
sheet.ColumnHeader.DefaultStyle.Font.Size = FontUnit.Parse("80%")
sheet.RowHeader.DefaultStyle.Font.Size = FontUnit.Parse("80%")
sheet.SheetCorner.DefaultStyle.Font.Size = FontUnit.Parse("80%")
' シート設定
sheet.PageSize = sheet.RowCount
' 列幅の設定
sheet.Columns(0).Width = 36
sheet.Columns(1).Width = 100
sheet.Columns(2).Width = 100
sheet.Columns(3).Width = 80
sheet.Columns(4).Width = 36
sheet.Columns(5).Width = 46
sheet.Columns(6).Width = 49
sheet.Columns(7).Width = 80
sheet.Columns(8).Width = 181
' 縦方向の揃え位置を中央に設定
sheet.DefaultStyle.VerticalAlign = VerticalAlign.Middle
' 文字色の設定
sheet.DefaultStyle.ForeColor = System.Drawing.Color.Black
End Sub
Protected Sub FpSpread1_ButtonCommand(ByVal sender As Object, ByVal e As FarPoint.Web.Spread.SpreadCommandEventArgs) Handles FpSpread1.ButtonCommand
If e.CommandName.StartsWith("SetFontName") Then
Dim strCom As String() = e.CommandName.Split("."c)
FpSpread1.ActiveSheetView.DefaultStyle.Font.Name = strCom(1)
ElseIf e.CommandName.StartsWith("SetFontItalic") Then
Dim strCom As String() = e.CommandName.Split("."c)
FpSpread1.ActiveSheetView.DefaultStyle.Font.Italic = Convert.ToBoolean(strCom(1))
ElseIf e.CommandName.StartsWith("SetFontBold") Then
Dim strCom As String() = e.CommandName.Split("."c)
FpSpread1.ActiveSheetView.DefaultStyle.Font.Bold = Convert.ToBoolean(strCom(1))
ElseIf e.CommandName.StartsWith("SetUnderline") Then
Dim strCom As String() = e.CommandName.Split("."c)
FpSpread1.ActiveSheetView.DefaultStyle.Font.Underline = Convert.ToBoolean(strCom(1))
ElseIf e.CommandName.StartsWith("SetStrikeout") Then
Dim strCom As String() = e.CommandName.Split("."c)
FpSpread1.ActiveSheetView.DefaultStyle.Font.Strikeout = Convert.ToBoolean(strCom(1))
ElseIf e.CommandName.StartsWith("SetForeColor") Then
Dim strCom As String() = e.CommandName.Split("."c)
Dim bc As System.Drawing.Color = System.Drawing.Color.FromName(strCom(1))
FpSpread1.ActiveSheetView.DefaultStyle.ForeColor = bc
End If
End Sub
End Class
|
<%@ Page MasterPageFile="~/MasterPage.master" Language="c#" AutoEventWireup="true"
Inherits="font" CodeFile="font.aspx.cs" %>
<%@ Register Assembly="FarPoint.Web.SpreadJ" Namespace="FarPoint.Web.Spread" TagPrefix="FarPoint" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<table>
<tr>
<td>フォント</td>
<td>
<asp:DropDownList ID="DDLft" runat="server" onchange="SetFontName(this[this.selectedIndex].value);">
<asp:ListItem value="MS Pゴシック">MS Pゴシック</asp:ListItem>
<asp:ListItem value="MS ゴシック">MS ゴシック</asp:ListItem>
<asp:ListItem value="MS 明朝">MS 明朝</asp:ListItem>
<asp:ListItem value="MS P明朝">MS P明朝</asp:ListItem>
</asp:DropDownList>
</td>
<td><asp:CheckBox ID="chkItalic" runat="server" Text="斜体" onclick="SetFontItalic(this.checked);" /></td>
<td><asp:CheckBox ID="chkBold" runat="server" Text="太字" onclick="SetFontBold(this.checked);" /></td>
<td><asp:CheckBox ID="chkUnder" runat="server" Text="アンダーライン" onclick="SetUnderline(this.checked);" /></td>
<td><asp:CheckBox ID="chkso" runat="server" Text="取り消し線" onclick="SetStrikeout(this.checked);" /></td>
<td>文字の色</td>
<td>
<asp:DropDownList ID="DDLfc" runat="server" onchange="SetForeColor(this[this.selectedIndex].value);">
<asp:ListItem style="COLOR: #ffffff; BACKGROUND-COLOR: black" value="Black">Black</asp:ListItem>
<asp:ListItem style="BACKGROUND-COLOR: gray" value="Gray">Gray</asp:ListItem>
<asp:ListItem style="BACKGROUND-COLOR: darkgray" value="DarkGray">DarkGray</asp:ListItem>
<asp:ListItem style="BACKGROUND-COLOR: lightgrey" value="LightGray">LightGray</asp:ListItem>
<asp:ListItem style="BACKGROUND-COLOR: white" value="White">White</asp:ListItem>
<asp:ListItem style="BACKGROUND-COLOR: aquamarine" value="Aquamarine">Aquamarine</asp:ListItem>
<asp:ListItem style="BACKGROUND-COLOR: blue" value="Blue">Blue</asp:ListItem>
<asp:ListItem style="COLOR: #ffffff; BACKGROUND-COLOR: navy" value="Navy">Navy</asp:ListItem>
<asp:ListItem style="COLOR: #ffffff; BACKGROUND-COLOR: purple" value="Purple">Purple</asp:ListItem>
<asp:ListItem style="BACKGROUND-COLOR: deeppink" value="DeepPink">DeepPink</asp:ListItem>
<asp:ListItem style="BACKGROUND-COLOR: violet" value="Violet">Violet</asp:ListItem>
<asp:ListItem style="BACKGROUND-COLOR: pink" value="Pink">Pink</asp:ListItem>
<asp:ListItem style="COLOR: #ffffff; BACKGROUND-COLOR: darkgreen" value="DarkGreen">DarkGreen
</asp:ListItem>
<asp:ListItem style="COLOR: #ffffff; BACKGROUND-COLOR: green" value="Green">Green</asp:ListItem>
<asp:ListItem style="BACKGROUND-COLOR: yellowgreen" value="YellowGreen">YellowGreen</asp:ListItem>
<asp:ListItem style="BACKGROUND-COLOR: yellow" value="Yellow">Yellow</asp:ListItem>
<asp:ListItem style="BACKGROUND-COLOR: orange" value="Orange">Orange</asp:ListItem>
<asp:ListItem style="BACKGROUND-COLOR: red" value="Red">Red</asp:ListItem>
<asp:ListItem style="BACKGROUND-COLOR: brown" value="Brown">Brown</asp:ListItem>
<asp:ListItem style="BACKGROUND-COLOR: burlywood" value="BurlyWood">BurlyWood</asp:ListItem>
<asp:ListItem style="BACKGROUND-COLOR: beige" value="Beige">Beige</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
</table>
<farpoint:FpSpread ID="FpSpread1" runat="server" BorderColor="#A0A0A0" BorderStyle="Solid"
BorderWidth="1px" onbuttoncommand="FpSpread1_ButtonCommand">
<CommandBar BackColor="#F6F6F6" ButtonFaceColor="Control" ButtonHighlightColor="ControlLightLight"
ButtonShadowColor="ControlDark" />
<Sheets>
<farpoint:SheetView SheetName="Sheet1">
</farpoint:SheetView>
</Sheets>
</farpoint:FpSpread>
</asp:Content>
|