Gewusst wie: Aktualisieren von Daten

Letzte Änderung: Donnerstag, 3. Dezember 2009

Gilt für: SharePoint Server 2010

Dieses Beispiel zeigt, wie aktualisierte Daten aus externen Datenquellen mithilfe der Refresh-Methode für die geöffnete Arbeitsmappe abgerufen werden. Die Signatur der Excel-Webdienste für die Refresh-Methode lautet wie folgt:

public Status[] Refresh (string sessionId, string connectionName)
Public Function Refresh(ByVal sessionId As String, ByVal connectionName As String) As Status()
End Function

Wenn Sie eine direkte Verknüpfung zu Microsoft.Office.Excel.Server.WebServices.dll herstellen, lautet die Signatur für die Refresh-Methode wie folgt:

public void Refresh (string sessionId, string connectionName, 
    out Status[] status)
Public Sub Refresh(ByVal sessionId As String, ByVal connectionName As String, <System.Runtime.InteropServices.Out()> ByRef status() As Status)
End Sub

Das connectionName-Argument verweist auf den Verbindungsnamen in einer Microsoft Office Excel 2007-Arbeitsmappe.

Sie können die Refresh-Methode verwenden, um eine einzelne Datenverbindung in der Arbeitsmappe zu aktualisieren oder um alle Verbindungen zu aktualisieren. Dies ist insbesondere dann hilfreich, wenn die Verbindungen ohne die Funktionalität "Aktualisieren beim Öffnen" erstellt werden.

Wenn Sie eine Verbindung aktualisieren, werden die Daten und alle Objekte aktualisiert, die die Verbindung verwenden. Um alle verfügbaren Verbindungen in der Arbeitsmappe zu aktualisieren, übergeben Sie eine leere Verbindungszeichenfolge oder null für das Namensargument der Verbindung.

Der Versuch, die Aktualisierungsoperationen auszuführen, erfolgt unabhängig von der Art der verwendeten Authentifizierung und ohne weitere Bestätigung oder Aufforderung.

Weitere Informationen zur Refresh-Methode finden Sie in der Referenzdokumentation für die Excel-Webdienste.

Beispiel

Das folgende Codebeispiel zeigt, wie die Refresh-Methode mithilfe der Excel-Webdienste aufgerufen wird. Der Verbindungsname in diesem Beispiel lautet "MyInventoryConnection":

// Instantiate the Web service. 
ExcelService xlservice = new ExcelService();
Status[] outStatus;
RangeCoordinates rangeCoordinates = new RangeCoordinates();
string sheetName = "Sheet3";

// Set the path to the workbook to open.
// TODO: Change the path to the workbook
// to point to a workbook you have access to.
// The workbook must be in a trusted location.
string targetWorkbookPath = 
    http://myserver02/example/Shared%20Documents/Book1.xlsx";
            
// Set credentials for requests.
xlservice.Credentials = System.Net.CredentialCache.DefaultCredentials;

// Call open workbook, and point to the trusted   
// location of the workbook to open.
string sessionId = xlservice.OpenWorkbook(targetWorkbookPath, "en-US", "en-US", out outStatus);
 
// Prepare object to define range coordinates.
rangeCoordinates.Column = 0;
rangeCoordinates.Row = 0;
rangeCoordinates.Height = 8;
rangeCoordinates.Width = 10;

// Set the cell located in the first row and 
// ninth column to 300.
xlservice.SetCell(sessionId, sheetName, 0, 8, 300); 
xlservice.Refresh(sessionId, "MyInventoryConnection");
' Instantiate the Web service. 
Dim xlservice As New ExcelService()
Dim outStatus() As Status
Dim rangeCoordinates As New RangeCoordinates()
Dim sheetName As String = "Sheet3"

' Set the path to the workbook to open.
' TODO: Change the path to the workbook
' to point to a workbook you have access to.
' The workbook must be in a trusted location.
' Set credentials for requests.
Dim targetWorkbookPath As String = http: xlservice.Credentials = System.Net.CredentialCache.DefaultCredentials 'myserver02/example/Shared%20Documents/Book1.xlsx";

' Call open workbook, and point to the trusted   
' location of the workbook to open.
Dim sessionId As String = xlservice.OpenWorkbook(targetWorkbookPath, "en-US", "en-US", outStatus)

' Prepare object to define range coordinates.
rangeCoordinates.Column = 0
rangeCoordinates.Row = 0
rangeCoordinates.Height = 8
rangeCoordinates.Width = 10

' Set the cell located in the first row and 
' ninth column to 300.
xlservice.SetCell(sessionId, sheetName, 0, 8, 300)
xlservice.Refresh(sessionId, "MyInventoryConnection")

Wenn Sie eine direkte Verknüpfung zu Microsoft.Office.Excel.Server.WebServices.dll herstellen, lautet der entsprechende Code wie folgt:

// Instantiate the ExcelService class.
ExcelService xlservice = new ExcelService();
Status[] outStatus;
RangeCoordinates rangeCoordinates = new RangeCoordinates();
string sheetName = "Sheet3";

// Set the path to the workbook to open.
// TODO: Change the path to the workbook
// to point to a workbook you have access to.
// The workbook must be in a trusted location.
string targetWorkbookPath = 
    http://myserver02/example/Shared%20Documents/Book1.xlsx";
            
// Call the open workbook, and point to the trusted 
// location of the workbook to open.
string sessionId = xlservice.OpenWorkbook(targetWorkbookPath, "en-US", "en-US", out outStatus);
                
// Set the cell located in the first row and 
// ninth column to 300.
xlservice.SetCell(sessionId, sheetName, 0, 8, 300, out outStatus); 
xlservice.Refresh(sessionId, "MyInventoryConnection", out outStatus);

byte[] workbook = xlService.GetWorkbook(sessionId, WorkbookType.FullWorkbook, out status);

// Write the resulting Excel file to stdout 
// as a binary stream.
BinaryWriter binaryWriter = 
    new BinaryWriter(Console.OpenStandardOutput());
binaryWriter.Write(workbook);
binaryWriter.Close();
...
...
' Instantiate the ExcelService class.
Dim xlservice As New ExcelService()
Dim outStatus() As Status
Dim rangeCoordinates As New RangeCoordinates()
Dim sheetName As String = "Sheet3"

' Set the path to the workbook to open.
' TODO: Change the path to the workbook
' to point to a workbook you have access to.
' The workbook must be in a trusted location.
' Call the open workbook, and point to the trusted 
' location of the workbook to open.
Dim targetWorkbookPath As String = http: String sessionId = xlservice.OpenWorkbook(targetWorkbookPath, "en-US", "en-US", outStatus) 'myserver02/example/Shared%20Documents/Book1.xlsx";

' Set the cell located in the first row and 
' ninth column to 300.
xlservice.SetCell(sessionId, sheetName, 0, 8, 300, outStatus)
xlservice.Refresh(sessionId, "MyInventoryConnection", outStatus)

Dim workbook() As Byte = xlService.GetWorkbook(sessionId, WorkbookType.FullWorkbook, status)

' Write the resulting Excel file to stdout 
' as a binary stream.
Dim binaryWriter As New BinaryWriter(Console.OpenStandardOutput())
binaryWriter.Write(workbook)
binaryWriter.Close()
...
...

Siehe auch

Aufgaben

Exemplarische Vorgehensweise: Entwickeln einer benutzerdefinierten Anwendung mithilfe der Excel-Webdienste

Gewusst wie: Festlegen eines Speicherorts als vertrauenswürdig

Gewusst wie: Speichern im Excel-Client auf dem Server

Gewusst wie: Abrufen einer ganzen Arbeitsmappe oder einer Momentaufnahme

Konzepte

Zugreifen auf die SOAP-API

Excel Services Alerts

Bekannte Probleme und Tipps für Excel Services

Loopback-SOAP-Aufrufe und direkte Verknüpfung