スプレッドシートを画像にレンダリングする際のデフォルト フォントの設定

スプレッドシートを画像にレンダリングする際のデフォルト フォントの設定

次のサンプル コードは、ブックを作成し、最初のワークシートのセル A4 にテキストを追加し、そのフォントを無効または存在しないフォントに設定します。次に、ワークシートの 2 つの画像を取得します。最初の画像は、ImageOrPrintOptions.DefaultFontプロパティへクーリエ 新規 2 番目の画像は、ImageOrPrintOptions.DefaultFontプロパティへタイムズ ニュー ローマン.

これは、設定後の出力イメージです。ImageOrPrintOptions.DefaultFontプロパティへクーリエ 新規.

todo:画像_代替_文章

これは、設定後の出力イメージです。ImageOrPrintOptions.DefaultFontプロパティへタイムズ ニュー ローマン.

todo:画像_代替_文章

サンプルコード

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Create workbook object.
Workbook wb = new Workbook();
// Set default font of the workbook to none
Style s = wb.DefaultStyle;
s.Font.Name = "";
wb.DefaultStyle = s;
// Access first worksheet.
Worksheet ws = wb.Worksheets[0];
// Access cell A4 and add some text inside it.
Cell cell = ws.Cells["A4"];
cell.PutValue("This text has some unknown or invalid font which does not exist.");
// Set the font of cell A4 which is unknown.
Style st = cell.GetStyle();
st.Font.Name = "UnknownNotExist";
st.Font.Size = 20;
st.IsTextWrapped = true;
cell.SetStyle(st);
// Set first column width and fourth column height
ws.Cells.SetColumnWidth(0, 80);
ws.Cells.SetRowHeight(3, 60);
// Create image or print options.
ImageOrPrintOptions opts = new ImageOrPrintOptions();
opts.OnePagePerSheet = true;
opts.ImageType = Drawing.ImageType.Png;
// Render worksheet image with Courier New as default font.
opts.DefaultFont = "Courier New";
SheetRender sr = new SheetRender(ws, opts);
sr.ToImage(0, "out_courier_new_out.png");
// Render worksheet image again with Times New Roman as default font.
opts.DefaultFont = "Times New Roman";
sr = new SheetRender(ws, opts);
sr.ToImage(0, "times_new_roman_out.png");