I want to update an existing Excel file using SpreadsheetGear.
I load the Excel file using:
_activeWorkbook = Factory.GetWorkbook(#"./excel/test.xls");
workbookView1.ActiveWorkbook = _activeWorkbook;
but when I want to save it:
private void menuSave_Click(object sender, EventArgs e)
{
workbookView1.GetLock();
try
{
_activeWorkbook.Save();
}
finally
{
workbookView1.ReleaseLock();
}
}
I get this error: System.IO.IOException: The process cannot access the file 'C:...\bin\Debug\excel\test.xls' because it is being used by another process.
As the exception indicates, some other process (or possibly your same application, if you utilize multiple threads) has a lock on your file and so SpreadsheetGear cannot save it back to disk. Any number of other external processes could be the culprit, such as anti-virus software scanning your file or having it open in Excel itself when you try to save it. There is no way to determine the exact cause with just the information provided above.
What I can tell you is that SpreadsheetGear does not keep any file streams open after reading and writing files. The file stream and lock on the file is only open for as long as it takes to read/write its contents, which is usually very short if the file is small. Put another way, #".excel/test.xls" should be writable immediately after your Factory.GetWorkbook(...) line executes.
Related
I made the iOS app unity.
It also successfully selected data from sqlite.
But when I insert, the error below appears.
mono.data.sqlite.sqliteexception (0x80004005): attempt to write a read-only database
The path to the DB file is here.
string filepath = Application.dataPath + "/Raw/Data.db";
if (!File.Exists(filepath))
{
File.Copy(Application.streamingAssetsPath + "/Raw/Data.db", filepath);
}
I wonder if I should set write permissions or change the path of the file.
What should I do if I have to grant write permission?
If I have to change the route, where should I go?
In the official documentation you have this:
On many platforms, the streaming assets folder location is read-only; you can not modify or write new files there at runtime. Use Application.persistentDataPath for a folder location that is writable.
Solution: Use Application.persistentDataPath instead of streaming asset folder.
Is there an iOS method to flush all open output files-- so that when the call returns, all pending buffered data is written to persistent storage? I mean this in general terms-- where I don't have access to the specific file handles. I've tried sync() from Swift (a POSIX call) but that appears not guaranteed to actually make sure the data hits persistent storage before it returns (see http://pubs.opengroup.org/onlinepubs/009696899/functions/sync.html).
Not sure if this solves the problem in general, but it's addressing my need. Here's what I'm doing:
// Write to file (in my case, this is a log file where I don't have access to the file handle).
// I'm using logging to a file with SwiftyBeaver. https://github.com/SwiftyBeaver/SwiftyBeaver
DispatchQueue.main.async {
// Read from the file-- it has the flushed contents. I'm doing:
do {
let fileContents = try String(contentsOfFile: path)
} catch (let error) {
}
}
It looks like files are flushed at the end of the event loop.
Summary:
Mail appears to flatten document packages when sending them.
Background:
I'm using subclassed UIDocument and FileWrappers to provide a document package for storing metadata, data and a thumbnail preview for my documents. I've made the necessary UTI incantations to get the document packages working locally.
I've added sharing support via UIActivityViewController. I'm sending the document using its fileURL. In testing with round-tripping my document package everything seems to be working well: export and import work great... almost.
Problem:
With Mail attachments, the document package arrives in a semi-flattened state (import no longer sees it as the document package). On examination of the document (on my Mac in TextWrangler) there is still directory structure and I can see the metadata, data, thumbnail but FileManager doesn't see it.
I've tried sharing the Mail attachment back to my app (via Copy to App) before the email is sent and that works fine.
Question:
Is Mail doing something unusual when moving the document package across a mail server?
I'm hoping to eventually support Open in Place and Files so I don't really want to get into wrapping shared documents in a Data blob etc. Does anyone know what's happening here and how to handle it while keeping my document a package?
Update:
I've confirmed that Apple Mail is zipping the package but not changing the extension. So the file received is a zip of the original. How can I make sure Apple Mail sees this as a package and doesn't zip? And, if I can't, how can I recognize the file being imported is a zip without the zip extension?
Answer:
Mail is indeed zipping the document package.
According to my research, we don't need to alter the document-package approach (i.e. not have a flattened special export type). On import, we test if it's a directory. If it's not a directory then we try unzipping it from its source url instead of just copying it. It should be noted that unzipping needs to be handled through a third-party library.
I wish there was a built-in API for handling this but this seems to be the way to deal with it.
(Inelegant) example code:
// Check if directory
if let _ = try? FileManager.default.contentsOfDirectory(atPath: url.path) {
// It is - try copying to the documents url
do {
try FileManager.default.copyItem(at: url, to: destination)
} catch {
self.delegate?.documentFileManagerDidFail(error: NSLocalizedString("Failed to copy file: \(error)", comment: "Document failure message"))
return
}
} else {
// It's not - try unzipping to the documents url
do {
try FileManager.default.unzipItem(at: url, to: destination)
} catch {
self.delegate?.documentFileManagerDidFail(error: NSLocalizedString("Failed to unzip file: \(error)", comment: "Document failure message"))
return
}
}
i would like to get all the data present in the trace window to my text file, even log recording can help but it can't display date and time in that file, so i've a plan to copy entire trace window to file.
i've tried to do ctrl+a and paste in notepad, but it is just copying some sort of area only not all.
i would like to know is there any chance to redirect how trace window is printing like that i can see in text file, or at least is there any way to copy entire file and paste in text file.
The trace windows just display the data, you configure it in the Measurement Setup.
But be aware that this will be only a part of the data anyway. There is a buffer where CANoe stores the data for the Trace window. You can configure the type of this buffer (memory or hard disk) and its size. Go to Options -> Measurement -> Data History to change your settings.
You can also configure the size of the visible data range there. But even with a very long range and a large 200 GB buffer, there might be a possibility that some data will not be available, because the Trace works as a ring buffer deleting the old data on overflow.
If you need the complete data, you should enable the Logging in the Measurement setup. Yes, the data files will be not human-readable. You will then need to open them in the Offline Mode in CANoe to analyze them. The timestamps will be of course logged, so you can easily use them for your analysis.
You could pretty-print it to the write window using CAPL:
on message *
{
int i;
write("[%07.3f] %03X", this.time / 100000.0, this.id);
for (i = 0; i < this.dlc; i++)
writeEx(0, 0, " %02X", this.byte(i));
}
And then export it to a file.
Or you write it directly to a file.
Hi I would suggest logging the necessary data into a CSV and then analyzing using Excel. You can make use of the File Access CAPL functions like openFileWrite for the same
I got a dictionary to store SoundEffects in, like:
public static Dictionary<string, SoundEffect> Hangok = new Dictionary<string, SoundEffect>();
I load sounds from files (normal .wav format), like:
GStatic.Hangok.Add(Azonosító, SoundEffect.FromStream(File.OpenRead(Azonosító)));
, where Azonosító was the filename.
All is just fine, files are loaded, except one; an exception is created:
Operation is not valid due to the current state of the object.
, what is not much of information for me. Could anyone explain this error message OR tell me why SoundEffect.FromStream fails to read? Why? When? Workaround?
Thanks in advance:
Péter
I use the ContentManager to load in SoundEffect's. Place the wav file in the content project and it should just load in.
E.g.
SoundEffect s = Content.Load<SoundEffect>("name");
Not a complete, but working solution to this problem. "Answering my question" only, because it may be useful for other developers, who also have no idea what the problem may be.
try
{
GStatic.Hangok.Add(Azonosító, SoundEffect.FromStream(File.OpenRead(Azonosító)));
}
catch
{
GStatic.Hangok.Add(Azonosító, new SoundEffect(File.ReadAllBytes(Azonosító), 11025, AudioChannels.Mono));
}
And well: I got no idea WHY you can not load that file in the normal way and why you can load the way like in the exception handler. Having a file in mono should not be that big problem. If someone knows, please drop a note/comment.