パブリック API Aspose.Cells 8.9.1 の変更点

追加された API

構成可能なフォント ソース

Aspose.Cells for Java は、スプレッドシートをレンダリングするための構成可能なフォント ソースのサポートを提供するために、多くのクラスを公開しました。以下は、Aspose.Cells for Java 8.9.1 で追加されたクラスのリストです。

  1. FontConfigs クラスは、フォント設定を指定します。
  2. FontSourceBase クラスは、ユーザーがさまざまなフォント ソースを指定できるようにするクラスの抽象基本クラスです。
  3. FileFontSource クラスは、ファイル システムに格納されている単一の TrueType フォント ファイルを表します。
  4. FolderFontSource クラスは、TrueType フォント ファイルを含むフォルダーを表します。
  5. MemoryFontSource クラスは、メモリに格納された単一の TrueType フォント ファイルを表します。
  6. FontSourceType 列挙体は、フォント ソースの種類を指定します。

上記の変更により、Aspose.Cells for Java では、以下に示すようにフォントを設定できます。

  1. FontConfigs.setFontFolder メソッドを使用して、1 つのカスタム フォント フォルダーを設定します。
  2. FontConfigs.setFontFolders メソッドを使用して、複数のカスタム フォント フォルダーを設定します。
  3. FontConfigs.setFontSources メソッドを使用して、カスタム フォント フォルダー、単一のフォント ファイル、またはバイト配列のフォント データからフォント ソースを設定します。

前述の方法の簡単な使用シナリオを次に示します。

Java

 //Defining string variables to store paths to font folders & font file

String fontFolder1 = "D:/Arial";

String fontFolder2 = "D:/Calibri";

String fontFile = "D:/Arial/arial.ttf";

//Setting first font folder with setFontFolder method

//Second parameter directs the API to search the sub folders for font files

FontConfigs.setFontFolder(fontFolder1, true);

//Setting both font folders with setFontFolders method

//Second parameter prohibits the API to search the sub folders for font files

FontConfigs.setFontFolders(new String[]{ fontFolder1, fontFolder2 }, false);

//Defining FolderFontSource

FolderFontSource sourceFolder = new FolderFontSource(fontFolder1, false);

//Defining FileFontSource

FileFontSource sourceFile = new FileFontSource(fontFile);

//Defining MemoryFontSource

byte[]bytes = Files.readAllBytes(new File(fontFile).toPath());

MemoryFontSource sourceMemory = new MemoryFontSource(bytes);

//Setting font sources

FontConfigs.setFontSources(new FontSourceBase[]{ sourceFolder, sourceFile, sourceMemory});

Aspose.Cells for Java では、フォントの置換を構成することもできます。このメカニズムは、変換が必要なマシンで必要なフォントが利用できない場合に役立ちます。ユーザーは、元々必要だったフォントの代わりに、フォント名のリストを提供できます。これを実現するために、Aspose.Cells API は、2 つのパラメーターを受け入れる FontConfigs.setFontSubstitutes メソッドを公開しました。最初のパラメーターは文字列型で、置換する必要があるフォントの名前にする必要があります。 2 番目のパラメーターは、string 型の配列です。ユーザーは、元のフォント名 (最初のパラメーターで指定) の代わりに、フォント名のリストを提供できます。

FontConfigs.SetFontSubstitutes メソッドの簡単な使用シナリオを次に示します。

Java

 //Substituting the Arial font with Times New Roman & Calibri

FontConfigs.setFontSubstitutes("Arial", new String[]{ "Times New Roman", "Calibri" });

Aspose.Cells for Java は、どのソースと代替が設定されているかに関する情報を収集する手段も提供しています。

  1. FontConfigs.getFontSources メソッドは、指定されたフォント ソースのリストを含む FontSourceBase タイプの配列を返します。ソースが設定されていない場合、FontConfigs.getFontSources メソッドは空の配列を返します。
  2. FontConfigs.getFontSubstitutes メソッドは文字列型のパラメータを受け入れ、置換が設定されているフォント名を指定できます。指定されたフォント名に代替が設定されていない場合、FontConfigs.getFontSubstitutes メソッドは null を返します。

IFilePathProvider インターフェイスと HtmlSaveOptions.FilePathProvider プロパティを追加

Aspose.Cells for Java 8.9.1 では、ワークシートを個別の HTML ファイルにエクスポートするための IFilePathProvider を取得/設定できます。これらの新しい API は、あるワークシートのハイパーリンクが別のワークシート内の場所を指しているシナリオで役立ちます。アプリケーションの要件は、各ワークシートを個別の HTML ファイルにレンダリングすることです。 IFilePathProvider を実装すると、別の結果の HTML ファイル内の場所を指しているという事実に関係なく、前述のハイパーリンクをそのまま維持できます。

以下は、HtmlSaveOptions.FilePathProvider プロパティの簡単な使用シナリオです。

Java

 // Workbook のインスタンスにスプレッドシートをロードします

Workbook book = new Workbook(dir + "sample.xlsx");

//各ワークシートを個別の HTML ファイルに保存します

for (int i = 0; i< book.getWorksheets().getCount(); i++)

{

	book.getWorksheets().setActiveSheetIndex(i);

	//Create an instance of HtmlSaveOptions & set FilePathProvider property

	HtmlSaveOptions options = new HtmlSaveOptions();

	options.setExportActiveWorksheetOnly(true);

	options.setFilePathProvider(new IFilePathProvider() 

	{ 

		public String getFullName(String sheetName)

		{

		    if ("Sheet2".equals(sheetName))

		    {

		        return "sheet1.html";

		    }

		    else if ("Sheet3".equals(sheetName))

		    {

		        return "sheet2.html";

		    }



		    return "";

		}

	});



	 //Write HTML file to disc

	 book.save(dir + "sheet"+ i +".html", options);

}

CopyOptions.ReferToDestinationSheet プロパティと Cells.copyRows メソッドのオーバーロードを追加

Aspose.Cells for Java API は、コピーされる行にグラフとそのデータ ソースも含まれている場合に行のコピー操作を容易にするために、Cells.copyRows メソッドのオーバーロードと共にブール型の CopyOptions.ReferToDestinationSheet プロパティを公開しました。開発者は、これらの新しい API を利用して、グラフのデータ ソースをソースまたは宛先のワークシートに向けることができます。

以下は、簡単な使用シナリオです。

Java

 //Load a sample spreadsheet in an instance of Workbook

Workbook book = new Workbook(dir + "sample.xlsx");

//Access the worksheet containing the chart & its data source

Worksheet source = book.getWorksheets().get(0);

//Add a new worksheet to the collection

Worksheet destination = book.getWorksheets().get(book.getWorksheets().add());

//Initialize CopyOptions and set its ReferToDestinationSheet property to true

CopyOptions options = new CopyOptions();

options.setReferToDestinationSheet(true);

//Copy the rows

destination.getCells().copyRows(source.getCells(), 0, 0, source.getCells().getMaxDisplayRange().getRowCount(), options);

//Save the result on disc

book.save(dir + "output.xlsx");

CalculationOptions.Recursive プロパティを追加しました

Aspose.Cells for Java 8.9.1 では、ブール型の CalculationOptions.Recursive プロパティが公開されました。 CalculationOptions.Recursive プロパティを true に設定し、オブジェクトを Workbook.calculateFormula メソッドに渡すと、Aspose.Cells API は、他のセルに依存するセルを計算するときに、依存セルを再帰的に計算するように指示されます。

以下は、簡単な使用シナリオです。

Java

 //Load a sample spreadsheet in an instance of Workbook

Workbook book = new Workbook(dir + "sample.xlsx");

//Initialize CalculationOptions & set Recursive property to true

CalculationOptions options = new CalculationOptions();

options.setRecursive(true);

//Recalculate formulas

book.calculateFormula(options);

廃止された API

廃止された CellsHelper.FontDir プロパティ

代わりに、FontConfigs.setFontFolder(String, boolean) メソッドを false に再帰するフォルダーで使用することをお勧めします。

廃止された CellsHelper.FontDirs プロパティ

代わりに、FontConfigs.setFontFolders(String[], boolean) メソッドを false に再帰するフォルダーで使用します。

廃止された CellsHelper.FontFiles プロパティ

代わりに FontConfigs.setFontSources(FontSourceBase[]) メソッドを使用してください。