1

電子メールの本文からデータを解析する Outlook 2010 アドインを作成しました。現在、データを .CSV ファイルに書き込んで Excel ワークブックを開くと、データが自動的にインポートされます。.CSV をスキップして、アドインでワークブックを直接開き、データを書き込みたいと考えています。.NET 4.0 を使用しています。VS2010 Outlook アドインは Outlook 14.0 ライブラリを使用します。Excel 14.0 ライブラリの参照を含めようとすると、コンパイラで Office.dll が重複しているというエラーが表示されます。問題を言い換えてから 3 日経っても、インターネットで検索しても答えが得られません。これは私を困惑させました!「ここで助けてくれる?:-/

これが私のアドイン コードです: (正しくフォーマットされていることを願っています。これは私の最初の投稿です)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Reflection;
using System.Windows.Forms;
using System.Xml.Linq;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;


public partial class ThisAddIn
{
    Outlook.Explorer currentExplorer = null;
    private void ThisAddIn_Startup(object sender, System.EventArgs e)
    {
        currentExplorer = Application.ActiveExplorer();
        currentExplorer.SelectionChange += new      Outlook.ExplorerEvents_10_SelectionChangeEventHandler(CurrentExplorer_Event);
    }

    private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
    {
    }
    private void CurrentExplorer_Event()
    {
        Outlook.Selection selection = this.Application.ActiveExplorer().Selection;
        Outlook._Application olApp = new Outlook.Application();
        if (Application.ActiveExplorer().Selection.Count > 0)
        {
            Object selObject = Application.ActiveExplorer().Selection[1];
            if (selObject is Outlook.MailItem)
            {
                Outlook.MailItem message = (Outlook.MailItem)selObject;
                //MessageBox.Show(message.Subject);
                if (message.Subject == "Powerball Drawing Info")
                {
                    string fileString = string.Empty;
                    string body = string.Empty;
                    string[] numbers = new string[7];
                    int start = 0;
                    int y = 0;
                    // char ch;

                    for (int x = 0; x < 7; x++)
                    {
                        numbers[x] = string.Empty;
                    }
                    //Outlook.MailItem message = (Outlook.MailItem)e.OutlookItem;
                    body = message.Body;
                    start = body.IndexOf(":");

                    for (int x = start; x < start + 40; x++)
                    {
                        if (Char.IsDigit(body[x]))  // copy entire number to array element
                        {
                            numbers[y] += body[x];
                        }

                        if (Char.IsWhiteSpace(body[x]) && numbers[y].Length > 0) // increment number array index
                        {
                            y++;
                            if (y == 5) // skip the word " Powerball " and jump the array index to match spreadsheet
                            {
                                y = 6;
                                x += 10;
                                continue;
                            }
                        }
                        if (y == 6 && Char.IsDigit(body[x + 1]) == false) // test for finish of Powerball number
                        {
                            x = start + 40;
                        }
                    }
                    for (int x = 0; x < 7; x++) // build a string to write to file and display
                    {
                        fileString += numbers[x];
                        if (x != 6)
                        {
                            fileString += ", ";
                        }
                    }

                    System.IO.File.WriteAllText(@"C:\Users\rrichard39\Documents\Powerball.csv", fileString);
                    Process.Start(@"C:\Users\rrichard39\Documents\Powerball_Test.xlsm");

                }
            }
        }
    }

    #region VSTO generated code

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InternalStartup()
    {
        this.Startup += new System.EventHandler(ThisAddIn_Startup);
        this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
    }

    #endregion
}
4

2 に答える 2

0

TIMの場合、正確なエラー メッセージは次のとおりです。

Error 1 An assembly with the same identity 'office, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' has already been imported. Try removing one of the duplicate references. c:\Program Files (x86)\Microsoft Visual Studio 10.0\Visual Studio Tools for Office\PIA\Office14\Office.dll

于 2012-07-28T04:21:51.667 に答える
0

ティム - 元の投稿で述べたように、エラーは「コンパイラが "重複した Office.dll" のエラーを表示します」 ありがとう、とにかく、ティム。どの Outlook Interop Library VS2010 Outlook アドイン プロジェクト ビルダー/テンプレートが使用するかはわかりませんが (COM を推測していますが、よくわかりません)、新しい Outlook 2010 アドインを開始し、Excel Interop の NET バージョンを使用しました。ライブラリ 14.0 リファレンスとすべてが魅力のように機能します。今後の参考のために、プロジェクト ビルダー/テンプレートが使用するライブラリ (COM または NET) を特定する方法を理解したいと思っています。情報を得るために Outlook Interop Library Reference のプロパティを調べてみましたが、見つかったのはバージョン番号だけでした。

于 2012-07-28T04:16:09.497 に答える