0

我想在我的 c++ 应用程序 c++/cli 应用程序中实现如下所示的内容。我正在使用视觉工作室 2010。

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 回答