0

以下に示すように、c++アプリケーションc++/cliアプリケーションで何かを実装したいと思います。VisualStudio2010を使用しています。

static void ReadExcelFileDOM(string fileName)
{
    using (SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Open(fileName, false))
    {
        WorkbookPart workbookPart = spreadsheetDocument.WorkbookPart;
        WorksheetPart worksheetPart = workbookPart.WorksheetParts.First();
        SheetData sheetData = worksheetPart.Worksheet.Elements<SheetData>().First();
        string text;
        foreach (Row r in sheetData.Elements<Row>())
        {
            foreach (Cell c in r.Elements<Cell>())
            {
                text = c.CellValue.Text;
                Console.Write(text + " ");
            }
        }
        Console.WriteLine();
        Console.ReadKey();
    }
}

私は以下のように進めました:

#include "stdafx.h"
#define S DocumentFormat::OpenXml::Spreadsheet::Sheets
#define Sheetdata DocumentFormat::OpenXml::Spreadsheet::SheetData
#define Wsheet DocumentFormat::OpenXml::Spreadsheet::WorkbookPart::WorksheetPart
#define E DocumentFormat::OpenXml::OpenXmlElement
#define As DocumentFormat::OpenXml::OpenXmlAttributes
#define A DocumentFormat::OpenXml::OpenXmlAttribute
using namespace System;
using namespace System::Collections::Generic;
using namespace System::Linq;
using namespace System::IO;
using namespace System::Text;
using namespace System::Diagnostics;
using namespace DocumentFormat::OpenXml;
using namespace DocumentFormat::OpenXml::Packaging;
using namespace DocumentFormat::OpenXml::Spreadsheet;
int _tmain(int argc, _TCHAR* argv[])
{
    DocumentFormat::OpenXml::Packaging::SpreadsheetDocument^ mySpreadsheet = SpreadsheetDocument::Open("sample.xlsx", false);
    WorkbookPart^ wp = mySpreadsheet->WorkbookPart;//
    IEnumerable<Sheet>^ sheets = wp->GetFirstChild<Sheet>().Elements<Sheet>();

    return 0;
}

ビルドは次のエラーで失敗します:

1>clitest.cpp(33): error C3225: generic type argument for 'T' cannot be 'DocumentFormat::OpenXml::Spreadsheet::Sheet', it must be a value type or a handle to a reference type
1>clitest.cpp(33): error C2039: 'GetFirstChild' : is not a member of 'DocumentFormat::OpenXml::Packaging::WorkbookPart'
1>          c:\program files (x86)\open xml sdk\v2.0\lib\documentformat.openxml.dll : see declaration of 'DocumentFormat::OpenXml::Packaging::WorkbookPart'
1>clitest.cpp(33): error C2059: syntax error : ')'

誰かがこれについて私を助けてくれるならお願いします。私はこの問題に悩まされています。

強い テキストに関して

4

1 に答える 1

0

ジェネリック型はクラス参照型である必要があります。

IEnumerable<Sheet^>
于 2012-05-08T13:45:08.240 に答える