SQL fayllaridan olingan Excel fayllari buzilgan

Excel fayllarini (PDF kabi boshqa fayl turlari bilan birga) ikkilik ma'lumotlar sifatida saqlaydigan SQL DB bilan ishlayman. Ushbu fayllarni fayl tizimiga chiqarish uchun quyidagi koddan foydalanaman.

Muammo: PDF-fayllar juda yaxshi chiqadi. Lekin Excel uchun fayllar yaratiladi va ularni ochishga harakat qilsam, ular ishdan chiqadi yoki faqat axlat matnini beradilar.

Ushbu kodni ushbu ilovani fayllarni olish uchun yozgan avvalgi odamdan foydalanaman. Ushbu kod OpenMcdfdan foydalanyapti, men buni to'liq tushunolmayman, chunki u uchun foydali onlayn hujjatlar topilmadi.

//execution starts here
public override void SaveToDisk()
{

    byte[] keys = { (byte)0xd0, (byte)0xcf };


    //Searches through m_RawOleObject for combination of 'keys'
    int offset = Utils.SearchBytes(m_RawOleObject, keys); //returns '60' in case of Excel and '66' in case of Pdf

    //m_RawOleOjbect contains the data from the sqlDataReader (the binary data from the column.)
    m_RawOleObject = strip(m_RawOleObject, offset);

    MemoryStream ms = new MemoryStream(m_RawOleObject);
    CompoundFile cf = new CompoundFile(ms);
    GetStorageByName(cf.RootStorage, m_StorageName);

    if (Storage != null)
    {
        if (Storage is CFStream)
        {
            m_RawOleObject = (Storage as CFStream).GetData();
        }
        m_filename = System.IO.Path.Combine(STOREPATH, Utils.CombineFilenameWithExtension(Filename, m_extension));

        WriteToFile(m_filename, m_RawOleObject);
    }

}

protected void WriteToFile(string fn, byte[] obj)
{
    fn = GetNextAvailableFilename(fn, 0);
    FileStream fs = new FileStream(fn, FileMode.Create);
    BinaryWriter writer = new BinaryWriter(fs);
    writer.Write(obj);
    writer.Close();
    fs.Close();
    fs.Dispose();
}


protected void GetStorageByName(CFStorage cfs, string name)
{
    VisitedEntryAction va = delegate(CFItem target)
    {
        if (target is CFStorage)
        {
            GetStorageByName((CFStorage)target, name);
        }
        else
        {
            if (target.Name == name)
                Storage = target;
        }
    };

    //Visit NON-recursively (first level only)
    cfs.VisitEntries(va, false);
}

Bu erda nima bo'layotgani haqidagi har qanday fikrlar bormi? Nima uchun Excel buzilgan? Soatlarni qidirishga qaramasdan onlaynda ko'p topolmadim!

har qanday g'oyalar, takliflar yoki echimlar baholanadi.

Rahmat

0
WHAT ma'lumotlar bazasi va qaysi versiyasi? SQL faqat tuzilgan so'rovlar tilidir - ko'p ma'lumotlar bazasi tizimlari - SQL tomonidan ishlatiladigan til QAYD ... shunga o'xshash narsalar ko'pincha sotuvchiga xosdir - shuning uchun biz foydalanadigan ma'lumotlar bazasi tizimi ni bilishimiz kerak.
qo'shib qo'ydi muallif marc_s, manba
Avvalo, SqlDataReader so'zini eslatib, SQL Server bo'lishi mumkin
qo'shib qo'ydi muallif sq33G, manba
Yaxshi ... Men "SQL DB" Microsoft SQL Serverni aniq ko'rsatgan deb o'ylardim! va 2005 yil
qo'shib qo'ydi muallif user732528, manba

1 javoblar

SaveToDisk mantiqini quyidagi kabi o'zgartiring:

public override void SaveToDisk()
{
    byte[] keys = { (byte)0xd0, (byte)0xcf, (byte)0x11, (byte)0xe0, (byte)0xa1, (byte)0xb1, (byte)0x1a, (byte)0xe1 };
    int offset = Utils.SearchBytes(m_RawOleObject, keys);
    using (MemoryStream ms = new MemoryStream(strip(m_RawOleObject, offset)))
    {
        CompoundFile cf = new CompoundFile(ms, UpdateMode.ReadOnly, true, true);
        m_filename = GetNextAvailableFilename(System.IO.Path.Combine(STOREPATH, Utils.CombineFilenameWithExtension(Filename, m_extension)), 0);
        using (var fs = new FileStream(m_filename, FileMode.Create))
        {
            cf.Save(fs);
            cf.Close();
        }
    }

    //Workbook would be saved as hidden in previous step
    Microsoft.Office.Interop.Excel.Application xlApp = null;
    Microsoft.Office.Interop.Excel.Workbook xlWb = null;
    try
    {
        xlApp = new Microsoft.Office.Interop.Excel.Application();
        xlWb = xlApp.Workbooks.Open(m_filename);
        xlWb.CheckCompatibility = false;

        foreach (Window wn in xlApp.Windows)
        {
            wn.Visible = true;
        }
        xlWb.Save();
        xlWb.Close();
    }
    catch (Exception e)
    {
        //TODO: Log error and continue
    }
    finally
    {
        if (xlWb != null)
            Marshal.ReleaseComObject(xlWb);
        if (xlApp != null)
            Marshal.ReleaseComObject(xlApp);
        xlApp = null;
    }
}
0
qo'shib qo'ydi