123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.IO;
- namespace Biff8Excel.Excel
- {
- internal class ExcelBinaryWriter : BinaryWriter, IDisposable
- {
-
- string m_FileName;
- public ExcelBinaryWriter()
- {
-
-
-
- m_FileName = Path.GetTempFileName();
- FileInfo myFileInfo = new FileInfo(m_FileName);
- myFileInfo.Attributes = FileAttributes.Temporary;
- }
- public long Length
- {
- get
- {
-
- if (!OutStream.CanRead)
- OutStream = File.Open(m_FileName, FileMode.Open);
- return this.OutStream.Length;
- }
- }
- public long Position
- {
- get
- {
- if (OutStream.CanRead)
- return OutStream.Position;
- return 0;
- }
- set
- {
- if (!OutStream.CanWrite)
- OutStream = File.Open(m_FileName, FileMode.Open);
- OutStream.Position = value;
- }
- }
- public byte[] Stream
- {
- get
- {
- if (OutStream == System.IO.Stream.Null)
- return null;
- if ( !OutStream.CanRead )
- OutStream = File.Open(m_FileName, FileMode.Open);
- int rdlen = (int)this.OutStream.Length;
- byte[] b = new byte[rdlen];
- this.OutStream.Seek(0, SeekOrigin.Begin);
- this.OutStream.Read(b, 0, rdlen);
- return b;
- }
- }
- public override void Write(byte[] buffer)
- {
- if (buffer == null)
- return;
- int len = buffer.Length;
- if (len == 0)
- return;
-
-
- if ( OutStream == System.IO.Stream.Null)
- OutStream = File.Open(m_FileName, FileMode.Truncate);
-
- OutStream.Write(buffer, 0, len);
-
- }
- internal void clear()
- {
-
- OutStream.Close();
- if (File.Exists(m_FileName))
- File.Delete(m_FileName);
- m_FileName = string.Empty;
- }
-
-
-
- ~ExcelBinaryWriter()
- {
- clear();
- }
- }
- }
|