Node.js ve C++ kullanarak Excel grafiğini görsele dönüştürme

Grafikleri Görüntüye Dönüştürme

Buradaki örneklerde, bir pasta grafiği ve bir sütun grafiği resimlere dönüştürülmüştür.

Bir Dilim Grafiğini Bir Görüntü Dosyasına Dönüştürme

İlk olarak, Microsoft Excel’de bir pasta grafiği oluşturun ve sonra Aspose.Cells for Node.js via C++ kullanarak görsel dosyasına dönüştürün. Bu örnekteki kod, şablon Microsoft Excel dosyasındaki pasta grafiğe dayalı bir EMF resmi oluşturur.

Çıktı: pasta dilimi grafiği resmi
todo:image_alt_text
  1. Microsoft Excel’de bir pasta grafiği oluşturun:
    1. Microsoft Excel’de yeni bir çalışma kitabı açın.
    2. Bir çalışsayfaya bazı veriler girin.
    3. Veriye dayanarak bir pasta grafiği oluşturun.
    4. Dosyayı kaydedin.
Giriş dosyası.
todo:image_alt_text
  1. Aspose.Cells’i indirin ve kurun:
    1. Aspose.Cells for Node.js via C++‘ü İndiriniz.
    2. Geliştirme bilgisayarınıza kurun.

Tüm Aspose bileşenleri, kurulduğunda değerlendirme modunda çalışır. Değerlendirme modunun bir süresi yoktur ve yalnızca çıktı belgelerine filigran yerleştirir.

  1. Bir proje oluşturun:
    1. Tercih edilen IDE’nizi başlatın.
    2. Yeni bir komut satırı uygulaması oluşturun. Bu örnekte Node.js kullanılmıştır fakat herhangi bir JavaScript çalışma ortamıyla da oluşturabilirsiniz.
    3. Bir referans ekleyin. Bu proje Aspose.Cells kullanır, bu yüzden Aspose.Cells for Node.js via C++‘e referans ekleyin.
    4. Grafikleri bulan ve dönüştüren kodu yazın. Aşağıdaki kod, görevi gerçekleştirmek için bileşen tarafından kullanılan kod örneğidir. Çok az kod satırı kullanılmıştır.
const path = require("path");
const AsposeCells = require("aspose.cells.node");

// The path to the documents directory.
const dataDir = path.join(__dirname, "data");

// Open the existing excel file which contains the pie chart.
const workbook = new AsposeCells.Workbook(path.join(dataDir, "PieChart.xlsx"));

// Get the designer chart (first chart) in the first worksheet of the workbook.
const chart = workbook.getWorksheets().get(0).getCharts().get(0);

// Convert the chart to an image file.
chart.toImage(path.join(dataDir, "PieChart.out.emf"), AsposeCells.ImageType.Emf);

Bir Sütun Grafiğini Bir Görüntü Dosyasına Dönüştürme

İlk olarak, Microsoft Excel’de bir sütun grafiği oluşturun ve yukarıdaki gibi bir görüntü dosyasına dönüştürün. Örnek kodu çalıştırdıktan sonra, şablon Excel dosyasındaki sütun grafiğine göre bir JPEG dosyası oluşturulur.

Çıktı dosyası: bir sütun grafiği görüntüsü.
todo:image_alt_text
  1. Microsoft Excel’de bir sütun grafiği oluşturun:
    1. Microsoft Excel’de yeni bir çalışma kitabı açın.
    2. Bir çalışsayfaya bazı veriler girin.
    3. Verilere dayalı bir sütun grafiği oluşturun.
    4. Dosyayı kaydedin.
Giriş dosyası.
todo:image_alt_text
  1. Yukarıda açıklandığı gibi referanslarla bir projeyi kurun.
  2. Grafik dinamik olarak bir görüntü olarak dönüştürün. Bileşen tarafından görevi gerçekleştirmek için kullanılan kod aşağıda verilmiştir. Kod öncekiyle benzerdir:
const path = require("path");
const AsposeCells = require("aspose.cells.node");

// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
// Open the existing excel file which contains the column chart.
const workbook = new AsposeCells.Workbook(path.join(dataDir, "ColumnChart.xlsx"));

// Get the designer chart (first chart) in the first worksheet of the workbook.
const chart = workbook.getWorksheets().get(0).getCharts().get(0);

// Convert the chart to an image file.
chart.toImage(path.join(dataDir, "ColumnChart.out.jpeg"), AsposeCells.ImageType.Jpeg);