把 Epplus 的 example5 翻成 c++.net

其實我本來想用 native c++ call 的
可是 System.IO.FileIO 一直無法初始化?
mscorlib.dll 一直 load 的有錯誤,
所以還是乖乖吃 .net 套餐吧!

// clr_call_epplus.cpp: 主要專案檔。
 
#include "stdafx.h"
 
using namespace System;
using namespace System::IO;
using namespace OfficeOpenXml;    
using namespace OfficeOpenXml::Drawing;
using namespace OfficeOpenXml::Drawing::Chart;
using namespace System::Drawing;
 
int main(array<System::String ^> ^args)
{
        FileInfo^ templateFile = gcnew FileInfo(L"c:\\temp\\SampleApp\\sample1.xlsx");
        FileInfo^ newFile = gcnew FileInfo(L"c:\\temp\\SampleApp\\sample5.xlsx");
        if (newFile->Exists)
        {
                newFile->Delete();  // ensures we create a new workbook
                newFile = gcnew FileInfo(L"c:\\temp\\SampleApp\\sample5.xlsx");
        }
        ExcelPackage^ package = gcnew ExcelPackage(newFile, templateFile);
        {
                //Open worksheet 1
                ExcelWorksheet^ worksheet = package->Workbook->Worksheets[1];
                worksheet->InsertRow(5, 2);
 
                worksheet->Cells["A5"]->Value = "12010";
                worksheet->Cells["B5"]->Value = "Drill";
                worksheet->Cells["C5"]->Value = 20;
                worksheet->Cells["D5"]->Value = 8;
 
                worksheet->Cells["A6"]->Value = "12011";
                worksheet->Cells["B6"]->Value = "Crowbar";
                worksheet->Cells["C6"]->Value = 7;
                worksheet->Cells["D6"]->Value = 23.48;
 
                worksheet->Cells["E2:E6"]->FormulaR1C1 = "RC[-2]*RC[-1]";                
 
                ExcelNamedRange^ name = worksheet->Names->Add("SubTotalName", worksheet->Cells["C7:E7"]);
                name->Style->Font->Italic = true;
                name->Formula = "SUBTOTAL(9,C2:C6)";
 
                //Format the new rows
                worksheet->Cells["C5:C6"]->Style->Numberformat->Format = "#,##0";
                worksheet->Cells["D5:E6"]->Style->Numberformat->Format = "#,##0.00";
 
                ExcelPieChart^ chart = (ExcelPieChart^)(worksheet->Drawings->AddChart("PieChart", eChartType::Pie3D));
 
                chart->Title->Text = "Total";
                //From row 1 colum 5 with five pixels offset
                chart->SetPosition(0, 0, 5, 5);
                chart->SetSize(600, 300);
 
                ExcelAddress^ valueAddress = gcnew ExcelAddress(2, 5, 6, 5);
                ExcelChartSerie^ ser = (ExcelPieChartSerie^)(chart->Series->Add(valueAddress->Address, "B2:B6"));
                chart->DataLabel->ShowCategory = true;
                chart->DataLabel->ShowPercent = true;
 
                chart->Legend->Border->LineStyle = eLineStyle::Solid;
                chart->Legend->Border->Fill->Style = eFillStyle::SolidFill;
                chart->Legend->Border->Fill->Color = System::Drawing::Color::Red;
 
                //Switch the PageLayoutView back to normal
                worksheet->View->PageLayoutView = false;
                // save our new workbook and we are done!
                package->Save();
        }
 
 
    Console::WriteLine(L"Hello World");
    return 0;
}

讓地獄深紅的天亮 發表在 痞客邦 PIXNET 留言(0) 人氣()