Cell styles in OpenXML spreadsheet (SpreadsheetML)

Right, I managed to figure this out, after a lot of experimentation. It turns out that excel reserves styles 0 and 1 for normal cells and “Gray125” pattern fill respectively. Most of the above code can be removed, as we only need a CellFormat really. Working code: Console.WriteLine(“Creating document”); using (var spreadsheet = SpreadsheetDocument.Create(“output.xlsx”, SpreadsheetDocumentType.Workbook)) … Read more

C# EPPlus OpenXML count rows

With a worksheet object called worksheet, worksheet.Dimension.Start.Row and worksheet.Dimension.End.Row should give you the information you need. worksheet.Dimension.Address will give you a string containing the worksheet dimensions in the traditional Excel range format (e.g. ‘A1:I5’ for rows 1-5, columns 1-9). There is a documentation file available. In many cases it might be just as quick to … Read more

Save modified WordprocessingDocument to new file

If you use a MemoryStream you can save the changes to a new file like this: byte[] byteArray = File.ReadAllBytes(“c:\\data\\hello.docx”); using (MemoryStream stream = new MemoryStream()) { stream.Write(byteArray, 0, (int)byteArray.Length); using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(stream, true)) { // Do work here } // Save the file with the new name File.WriteAllBytes(“C:\\data\\newFileName.docx”, stream.ToArray()); }

Inserting newlines in Word using OpenXML

To insert newlines, you have to add a Break instance to the Run. Example: run.AppendChild(new Text(“Hello”)); run.AppendChild(new Break()); run.AppendChild(new Text(“world”)); The XML produced will be something like: <w:r> <w:t>Hello</w:t> <w:br/> <w:t>world</w:t> </w:r>

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)