Skip to content

Commit

Permalink
Remove obsolete stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
PrzemyslawKlys committed Sep 22, 2024
1 parent 428d412 commit 35d8739
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 39 deletions.
25 changes: 9 additions & 16 deletions OfficeIMO.Excel/ExcelDocument.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Packaging;
Expand All @@ -16,15 +16,12 @@ public List<ExcelSheet> Sheets {
List<ExcelSheet> listExcel = new List<ExcelSheet>();
if (_spreadSheetDocument.WorkbookPart.Workbook.Sheets != null) {
var elements = _spreadSheetDocument.WorkbookPart.Workbook.Sheets.OfType<Sheet>().ToList();


foreach (Sheet s in elements) {
ExcelSheet excelSheet = new ExcelSheet(this, _spreadSheetDocument, s);
id.Add(s.SheetId);
listExcel.Add(excelSheet);
}
foreach (Sheet s in elements) {
ExcelSheet excelSheet = new ExcelSheet(this, _spreadSheetDocument, s);
id.Add(s.SheetId);
listExcel.Add(excelSheet);
}

}

return listExcel;
}
Expand All @@ -41,7 +38,6 @@ public static ExcelDocument Create(string filePath) {
// Create a spreadsheet document by supplying the filepath.
// By default, AutoSave = true, Editable = true, and Type = xlsx.
SpreadsheetDocument spreadSheetDocument = SpreadsheetDocument.Create(filePath, SpreadsheetDocumentType.Workbook);

document._spreadSheetDocument = spreadSheetDocument;

// Add a WorkbookPart to the document.
Expand Down Expand Up @@ -73,9 +69,6 @@ public static ExcelDocument Load(string filePath, bool readOnly = false, bool au
document._spreadSheetDocument = spreadSheetDocument;

//// Add a WorkbookPart to the document.
//WorkbookPart workbookpart = spreadSheetDocument.AddWorkbookPart();
//workbookpart.Workbook = new Workbook();

document._workBookPart = document._spreadSheetDocument.WorkbookPart;

return document;
Expand All @@ -84,15 +77,15 @@ public static ExcelDocument Load(string filePath, bool readOnly = false, bool au
public static ExcelDocument Create(string filePath, string workSheetName) {
ExcelDocument excelDocument = Create(filePath);
excelDocument.AddWorkSheet(workSheetName);
return excelDocument;
return excelDocument;
}

public ExcelSheet AddWorkSheet(string workSheetName = "") {
ExcelSheet excelSheet = new ExcelSheet(this, _workBookPart, _spreadSheetDocument, workSheetName);

return excelSheet;
}

public void Open(string filePath = "", bool openExcel = true) {
if (filePath == "") {
filePath = this.FilePath;
Expand All @@ -101,7 +94,7 @@ public void Open(string filePath = "", bool openExcel = true) {
}

public void Close() {
this._spreadSheetDocument.Close();
this._spreadSheetDocument.Dispose();
}

public void Save(string filePath, bool openExcel) {
Expand Down
20 changes: 9 additions & 11 deletions OfficeIMO.Word/WordComment.PrivateMethods.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -38,18 +38,16 @@ internal static string GetNewId(WordDocument document, Comments comments) {

internal static Comments GetCommentsPart(WordDocument document) {
Comments comments = null;
if (document._wordprocessingDocument.MainDocumentPart.GetPartsCountOfType<WordprocessingCommentsPart>() > 0) {
comments = document._wordprocessingDocument.MainDocumentPart.WordprocessingCommentsPart.Comments;

//if (comments.HasChildren) {
// Obtain an unused ID.
//id = (comments.Descendants<Comment>().Select(e => int.Parse(e.Id.Value)).Max() + 1).ToString();
//}
if (document._wordprocessingDocument.MainDocumentPart != null && document._wordprocessingDocument.MainDocumentPart.GetPartsOfType<WordprocessingCommentsPart>().Any()) {
if (document._wordprocessingDocument.MainDocumentPart.WordprocessingCommentsPart != null)
comments = document._wordprocessingDocument.MainDocumentPart.WordprocessingCommentsPart.Comments;
} else {
// No WordprocessingCommentsPart part exists, so add one to the package.
WordprocessingCommentsPart commentPart = document._wordprocessingDocument.MainDocumentPart.AddNewPart<WordprocessingCommentsPart>();
commentPart.Comments = new Comments();
comments = commentPart.Comments;
if (document._wordprocessingDocument.MainDocumentPart != null) {
WordprocessingCommentsPart commentPart = document._wordprocessingDocument.MainDocumentPart.AddNewPart<WordprocessingCommentsPart>();
commentPart.Comments = new Comments();
comments = commentPart.Comments;
}
}

return comments;
Expand Down
12 changes: 1 addition & 11 deletions OfficeIMO.Word/WordCustomProperties.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -138,7 +138,6 @@ public CustomDocumentProperty Add(string name, object value, PropertyTypes prope
}

private void Add(string name, CustomDocumentProperty newProp) {
string returnValue = null;
if (_customProperties != null) {
// This will trigger an exception if the property's Name
// property is null, but if that happens, the property is damaged,
Expand All @@ -148,10 +147,7 @@ private void Add(string name, CustomDocumentProperty newProp) {
// Does the property exist? If so, get the return value,
// and then delete the property.
if (prop != null) {
//returnValue = prop.InnerText;
prop.Remove();

//_customProperties.RemoveChild(prop);
}

// Append the new property, and
Expand All @@ -162,14 +158,8 @@ private void Add(string name, CustomDocumentProperty newProp) {
foreach (CustomDocumentProperty item in _customProperties) {
item.PropertyId = pid++;
}

//this._wordprocessingDocument.CustomFilePropertiesPart.Properties.Save();
_customProperties.Save();

//this._wordprocessingDocument.CustomFilePropertiesPart.Properties = _customProperties;
}

// return returnValue;
}

private void CreateCustomProperty(WordDocument document) {
Expand Down
2 changes: 1 addition & 1 deletion OfficeIMO.Word/WordDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ public void Dispose() {

if (this._wordprocessingDocument != null) {
try {
this._wordprocessingDocument.Close();
this._wordprocessingDocument.Dispose();
} catch {
// ignored
}
Expand Down

0 comments on commit 35d8739

Please sign in to comment.