5

I'm going through the sample projects of EPPlus and finally reached the part that I'm interested in. I would like to import contents of a .txt file. Sample 9 shows how to do this, but I get an error I can't seem to fix.

The error message:

The type or namespace name "GetFileInfo" doesn't exist in the namespace 'OfficeOpenXml.Utils'(are you missing an assembly reference?)

The code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OfficeOpenXml;
using System.IO;
using OfficeOpenXml.Table;
using OfficeOpenXml.Drawing.Chart;
using System.Globalization

...

FileInfo newFile = Utils.GetFileInfo(@"\sample9.xlsx");

Does anyone encountered this issue? Thanks in advance!

Edit: If I open directly the sample file I don't get any errors, only if I try to do it in my own project.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Botond
  • 95
  • 8
  • I would say _are you missing an assembly reference?_ – Steve Jul 14 '18 at 09:07
  • @Steve Possibly. Do you have an idea how? I've installed using NuGet package manager. Should I do anything else? – Botond Jul 14 '18 at 09:14
  • You could also just replace that with a call to the `FileInfo` constructor (and perhaps a check that the file exists) which is presumably all that method does. Having not seen it, I can only guess. – pinkfloydx33 Jul 14 '18 at 09:15
  • 2
    Actually, that file is here: https://github.com/JanKallman/EPPlus/blob/master/SampleApp/Utils.cs That method creates a new FileInfo and optionally deletes the file if it already exists...so copy paste it (or the whole file) IMO. If you're writing your own sample app (new project as opposed to opening the EPPlus sample project) that file won't exist for you because it's part of *the sample project itself* – pinkfloydx33 Jul 14 '18 at 09:18
  • I think that [this](https://stackoverflow.com/a/33303454/8043685) link can help you. [Click here](https://stackoverflow.com/a/33303454/8043685) – amir mehrabi Jul 14 '18 at 09:21
  • @pinkfloydx33 Thank you! I've managed to make it work! – Botond Jul 14 '18 at 09:29
  • Possible duplicate of [How to read from XLSX (Excel)?](https://stackoverflow.com/questions/33302235/how-to-read-from-xlsx-excel) – Vanity Slug - codidact.com Jul 18 '18 at 17:04

1 Answers1

5

Try this:

var file = new System.IO.FileInfo(fullpathandfilename);
  • 1
    Creating the `FileInfo` and passing it to `package.SaveAs` instead of using the existing `Utils.GetFileInfo` (since I didn't add `Utils`) works for me. – Wouter Vanherck Nov 05 '18 at 09:46