2017-10-10 8 views
0

イムから表計算ドキュメント: https://msdn.microsoft.com/en-us/library/office/ff478410.aspxオープンのOpenXML SDKで作業する方法については、次の資料、次のストリーム(オープンXML SDK)

私は次のコードを持っている:

// Open a SpreadsheetDocument based on a stream. 
SpreadsheetDocument spreadsheetDocument 
    = SpreadsheetDocument.Open(stream, true); 
// Add a new worksheet. 
WorksheetPart newWorksheetPart = spreadsheetDocument.WorkbookPart.AddNewPart<WorksheetPart>(); 
newWorksheetPart.Worksheet = new Worksheet(new SheetData()); 
newWorksheetPart.Worksheet.Save(); 

Sheets sheets = spreadsheetDocument.WorkbookPart.Workbook.GetFirstChild<Sheets>(); 
string relationshipId = spreadsheetDocument.WorkbookPart.GetIdOfPart(newWorksheetPart); 

// Get a unique ID for the new worksheet. 
uint sheetId = 1; 
if (sheets.Elements<Sheet>().Count() > 0) 
{ 
    sheetId = sheets.Elements<Sheet>().Select(s => s.SheetId.Value).Max() + 1; 
} 

// Give the new worksheet a name. 
string sheetName = "Sheet" + sheetId; 

// Append the new worksheet and associate it with the workbook. 
Sheet sheet = new Sheet() { Id = relationshipId, SheetId = sheetId, Name = sheetName }; 
sheets.Append(sheet); 
spreadsheetDocument.WorkbookPart.Workbook.Save(); 

// Close the document handle. 
spreadsheetDocument.Close(); 

をしかし、私次のエラーが発生し続ける:

Severity Code Description Project File Line Suppression State 
Error CS1729 'Worksheet' does not contain a constructor that takes 1 arguments MyProject C:\Users\brkar1\Documents\Visual Studio 2015\Projects\MyProject\MyProject\Controllers\HomeController.cs 139 Active 
Error CS0246 The type or namespace name 'SheetData' could not be found (are you missing a using directive or an assembly reference?) MyProject C:\Users\brkar1\Documents\Visual Studio 2015\Projects\MyProject\MyProject\Controllers\HomeController.cs 139 Active 
Error CS1061 'WorksheetPart' does not contain a definition for 'Worksheet' and no extension method 'Worksheet' accepting a first argument of type 'WorksheetPart' could be found (are you missing a using directive or an assembly reference?) MyProject C:\Users\brkar1\Documents\Visual Studio 2015\Projects\MyProject\MyProject\Controllers\HomeController.cs 140 Active 
Error CS1061 'WorkbookPart' does not contain a definition for 'Workbook' and no extension method 'Workbook' accepting a first argument of type 'WorkbookPart' could be found (are you missing a using directive or an assembly reference?) MyProject C:\Users\brkar1\Documents\Visual Studio 2015\Projects\MyProject\MyProject\Controllers\HomeController.cs 142 Active 
Error CS1061 'Sheets' does not contain a definition for 'Elements' and no extension method 'Elements' accepting a first argument of type 'Sheets' could be found (are you missing a using directive or an assembly reference?) MyProject C:\Users\brkar1\Documents\Visual Studio 2015\Projects\MyProject\MyProject\Controllers\HomeController.cs 147 Active 
Error CS0246 The type or namespace name 'Sheet' could not be found (are you missing a using directive or an assembly reference?) MyProject C:\Users\brkar1\Documents\Visual Studio 2015\Projects\MyProject\MyProject\Controllers\HomeController.cs 147 Active 
Error CS1061 'Sheets' does not contain a definition for 'Elements' and no extension method 'Elements' accepting a first argument of type 'Sheets' could be found (are you missing a using directive or an assembly reference?) MyProject C:\Users\brkar1\Documents\Visual Studio 2015\Projects\MyProject\MyProject\Controllers\HomeController.cs 149 Active 
Error CS0246 The type or namespace name 'Sheet' could not be found (are you missing a using directive or an assembly reference?) MyProject C:\Users\brkar1\Documents\Visual Studio 2015\Projects\MyProject\MyProject\Controllers\HomeController.cs 149 Active 
Error CS0246 The type or namespace name 'Sheet' could not be found (are you missing a using directive or an assembly reference?) MyProject C:\Users\brkar1\Documents\Visual Studio 2015\Projects\MyProject\MyProject\Controllers\HomeController.cs 156 Active 
Error CS0246 The type or namespace name 'Sheet' could not be found (are you missing a using directive or an assembly reference?) MyProject C:\Users\brkar1\Documents\Visual Studio 2015\Projects\MyProject\MyProject\Controllers\HomeController.cs 156 Active 
Error CS1061 'Sheets' does not contain a definition for 'Append' and no extension method 'Append' accepting a first argument of type 'Sheets' could be found (are you missing a using directive or an assembly reference?) MyProject C:\Users\brkar1\Documents\Visual Studio 2015\Projects\MyProject\MyProject\Controllers\HomeController.cs 157 Active 
Error CS1061 'WorkbookPart' does not contain a definition for 'Workbook' and no extension method 'Workbook' accepting a first argument of type 'WorkbookPart' could be found (are you missing a using directive or an assembly reference?) MyProject C:\Users\brkar1\Documents\Visual Studio 2015\Projects\MyProject\MyProject\Controllers\HomeController.cs 158 Active 

誰でもこの手伝いをすることができますか?このエラーメッセージが表示されるのはなぜですか?

+0

DocumentFormat.OpenXml.dllへの参照をプロジェクトに追加しましたか? –

+0

@GabrielRainha:はい – Bryan

+0

@GabrielRainha:私のプロジェクトでは、私はそれを参照していましたが、NugetでDocumentFormatを検索したとき、それはインストールされていませんでした。私は今それをインストールして、エラーがなくなった:) – Bryan

答えて

1

プロジェクトにDocumentFormat.OpenXml.dllへの参照が追加されていることを確認してください。

関連する問題