MESCIUS SPREAD for Windows Forms 17.0J サンプルコード集
画像を設定する

MESCIUS SPREAD for Windows Forms 17.0J サンプルコード集 > デザイン > セル > 画像を設定する

IRangeインターフェースのInsertPictureInCellメソッドを使用してセルに画像を設定できます。画像はセルに対してセル型を設定せずに設定でき、表示方法は以下の4つから選択できます。デフォルトではFitが有効になります。

新しいスタイルシステム(LegacyBehaviorsプロパティがStyleを含まない場合)で有効です。

【実行例】

 private void Form1_Load(object sender, EventArgs e)
 {
  fpSpread1.AsWorkbook().ActiveSheet.Columns["A:D"].ColumnWidth = 90;
  fpSpread1.AsWorkbook().ActiveSheet.Rows[1].RowHeight = 120;

  // Fit
  fpSpread1.AsWorkbook().ActiveSheet.Cells[0, 0].Value = "Fit";
  var image1 = fpSpread1.AsWorkbook().ActiveSheet.Cells[1, 0].InsertPictureInCell(@"..\..\logo.png");
  image1.Sizing = GrapeCity.CalcEngine.SizingMode.Fit;

  // Fill
  fpSpread1.AsWorkbook().ActiveSheet.Cells[0, 1].Value = "Fill";
  var image2 = fpSpread1.AsWorkbook().ActiveSheet.Cells[1, 1].InsertPictureInCell(@"..\..\logo.png");
  image2.Sizing = GrapeCity.CalcEngine.SizingMode.Fill;

  // Original
  fpSpread1.AsWorkbook().ActiveSheet.Cells[0, 2].Value = "Original";
  var image3 = fpSpread1.AsWorkbook().ActiveSheet.Cells[1, 2].InsertPictureInCell(@"..\..\logo.png");
  image3.Sizing = GrapeCity.CalcEngine.SizingMode.Original;

  // Custom
  fpSpread1.AsWorkbook().ActiveSheet.Cells[0, 3].Value = "Custom";
  var image4 = fpSpread1.AsWorkbook().ActiveSheet.Cells[1, 3].InsertPictureInCell(@"..\..\logo.png");
  image4.Sizing = GrapeCity.CalcEngine.SizingMode.Custom;
  image4.Width = 60;
  image4.Height = 60;
 }
 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  FpSpread1.AsWorkbook().ActiveSheet.Columns("A:D").ColumnWidth = 90
  FpSpread1.AsWorkbook().ActiveSheet.Rows(1).RowHeight = 120

  ' Fit
  FpSpread1.AsWorkbook().ActiveSheet.Cells(0, 0).Value = "Fit"
  Dim image1 As GrapeCity.CalcEngine.CellImage = FpSpread1.AsWorkbook().ActiveSheet.Cells(1, 0).InsertPictureInCell("..\..\logo.png")
  image1.Sizing = GrapeCity.CalcEngine.SizingMode.Fit

  ' Fill
  FpSpread1.AsWorkbook().ActiveSheet.Cells(0, 1).Value = "Fill"
  Dim image2 As GrapeCity.CalcEngine.CellImage = FpSpread1.AsWorkbook().ActiveSheet.Cells(1, 1).InsertPictureInCell("..\..\logo.png")
  image2.Sizing = GrapeCity.CalcEngine.SizingMode.Fill

  ' Original
  FpSpread1.AsWorkbook().ActiveSheet.Cells(0, 2).Value = "Original"
  Dim image3 As GrapeCity.CalcEngine.CellImage = FpSpread1.AsWorkbook().ActiveSheet.Cells(1, 2).InsertPictureInCell("..\..\logo.png")
  image3.Sizing = GrapeCity.CalcEngine.SizingMode.Original

  ' Custom
  FpSpread1.AsWorkbook().ActiveSheet.Cells(0, 3).Value = "Custom"
  Dim image4 As GrapeCity.CalcEngine.CellImage = FpSpread1.AsWorkbook().ActiveSheet.Cells(1, 3).InsertPictureInCell("..\..\logo.png")
  image4.Sizing = GrapeCity.CalcEngine.SizingMode.Custom
  image4.Width = 60
  image4.Height = 60
 End Sub