Ricevo un errore durante l'apertura del foglio di calcolo creato con OpenXML. L'errore è il seguente.Record riparati: informazioni sulla cella dal foglio di lavoro creato da zero
Repaired Records: Cell information from /xl/worksheets/sheet.xml part
Repaired Records: Cell information from /xl/worksheets/sheet2.xml part
Repaired Records: Cell information from /xl/worksheets/sheet3.xml part
L'unica cosa che sono riuscito a trovare on-line che era disponibile era questo problema è stata la discussione di un algoritmo che altera una singola cella più volte la causa del problema. Detto questo, collegherò il mio Constructor per SpreadsheetDocument e le tre funzioni per l'aggiornamento di una cella (cosa che faccio una volta).
Posso fornire eventuali funzioni aggiuntive secondo necessità, ma credo che il problema sia da qualche parte nei due elencati di seguito.
A proposito,
GetWorksheetPartByName
InsertCellInWorksheet
GetCell
dovrebbero essere tutti a lavorare come previsto.
il vero programma
static void Main(string[] args)
{
//Full path for File
const string newFile = "@C:\test.xlsx";
//Constructor creates default worksheet called "mySheet"
var spreadsheet = new XLSXHelper(newFile);
//updating some cells.
spreadsheet.UpdateCell("mySheet", "D2", "R", 2);
}
Constructor
public XLSXHelper(string filepath)
{
newFile = filepath;
spreadsheetDocument = SpreadsheetDocument.Create(filepath, SpreadsheetDocumentType.Workbook);
this.workbookPart = spreadsheetDocument.AddWorkbookPart();
workbookPart.Workbook = new Workbook();
this.worksheetPart = workbookPart.AddNewPart<WorksheetPart>();
worksheetPart.Worksheet = new Worksheet(new SheetData());
Sheets sheets = spreadsheetDocument.WorkbookPart.Workbook.
AppendChild<Sheets>(new Sheets());
Sheet sheet = new Sheet()
{
Id = spreadsheetDocument.WorkbookPart.
GetIdOfPart(worksheetPart),
SheetId = 1,
Name = "mySheet"
};
sheets.Append(sheet);
workbookPart.Workbook.Save();
spreadsheetDocument.Close();
}
Aggiornamento cellulare
public void UpdateCell(string worksheetName, string textToInsert, string columnName, uint rowIndex)
{
using (SpreadsheetDocument spreadSheet = SpreadsheetDocument.Open(newFile, true))
{
WorksheetPart worksheetPart = GetWorksheetPartByName(spreadSheet, worksheetName);
if (worksheetPart != null)
{
InsertCellInWorksheet(columnName, rowIndex, worksheetPart);
Cell cell = GetCell(worksheetPart.Worksheet,columnName, rowIndex);
cell.CellValue = new CellValue(textToInsert);
worksheetPart.Worksheet.Save();
}
}
}
L'errore si è verificato nel mio codice, utilizzando [EPPlus] (http://epplus.codeplex.com/), quando ho creato un foglio di lavoro che ha un nome troppo lungo e/o contiene caratteri vietati. La soluzione era usare un nome breve e valido per il foglio di lavoro. –