|
Hello,
I created a new user defined function in excel using c#,what i want to get is when a user open an excel file, clic on a cell and write =myFunction() press enter, data should be displayed in the excel file. these data are retrieved from sql server database and stocked in a 2D array of object, my problem is when i try to display this array in excel range i got this exception
Exception de HRESULT : 0x800A03EC
Below is my code :
public static void LoadViewData()
{
var target = (ExcelReference)XlCall.Excel(XlCall.xlfCaller);
var sheetName = (string)XlCall.Excel(XlCall.xlSheetNm, target);
var application = (Microsoft.Office.Interop.Excel.Application)ExcelDnaUtil.Application;
var sheet = application.Sheets[Regex.Replace(sheetName, @"\[[^]]*\]", string.Empty)];
object[,] result = LoadFromDbData();
var startCell =sheet.Cells[target.RowFirst + 1, target.ColumnFirst];
var endCell =sheet.Cells[target.RowFirst+ result.GetUpperBound(0) - result.GetLowerBound(0) + 1,
target.ColumnFirst+ result.GetUpperBound(1) - result.GetLowerBound(1) + 1];
var writeRange = sheet.Range[startCell, endCell];
writeRange.Value2 = result;
}
target returns the correct value of the cell where the user has written the formula (=myFunction())
sheetName returns the correct activeSheet in which the user writes the formula
result contains the data retrieved from sql server, it is an array of object[854,8]
startcell and endcell represents the range from which cell to which cell data will be displayed
when debugging, all variables contain the correct values, the exception appears in this instruction :
writeRange.Value2 = result;
Anyone has already worked with this or can help please ?
Thanks
|
|
|
|
|
0x800A03EC in Excel is a rather generic error.
In this case, you can't assign an array to a single cells Value2 property. You actually have to iterate through each cell in the array and assign the value of that cell to the corresponding cell in the worksheet.
|
|
|
|
|
We have a medical device that is connected to the LAN but is not on Active Directory. The instrument is running Windows Embedded as a service.
When a user logs into the device we want to validate them against AD. I've found plenty of example of validating users, but they all seem to assume that the code is being run under an account of an AD user.
How to I validate a user against AD when the instrument isn't on AD?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
The device should able to connect AD to validate the user.
Or
you could create a web service that can connect to AD and let the medical device call that web service to verify the user.
|
|
|
|
|
Keviniano Gayo wrote: The device should able to connect AD to validate the user.
Unless someone logs into Windows on the device, it won't connect. Here's how I'm trying
using (var context = new PrincipalContext(ContextType.Domain, credentials.ServerName, credentials.UserName, credentials.Password))
{
validated = context.ValidateCredentials(userName, password);
}
Again, this works if someone is logged into Windows. if not, it doesn't
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
I see.. i haven't tried connecting to AD without logging into windows.
I used the same code as above to verify the user in AD.
Perhaps calling a custom web service to verify a user in AD would be the best route.
|
|
|
|
|
Hi,
I have a folder named "Data_base" stored somewhere in my pc. I need the full path of this folder by searching only its name in C#.
void getPath(string name)
{
// need code
}
string folderName="Data_base";
getPath(folderName);
Please Help . . .
|
|
|
|
|
See Directory Methods (System.IO)[^]. You will need to start at the root and enumerate all directories recursively until you find the one you are looking for.
|
|
|
|
|
thanks for your reply.
Got the solution, but ends up with another problem "Access to the path 'D:\System Volume Information' is denied" . And i didn't find any solution to this. So instead of placing the Data_base anywhere i decided to place it in the application installation folder itself.
Now the path can be easily read by using the code in runtime
string appFileName = Environment.GetCommandLineArgs()[0];
string directory = Path.GetDirectoryName(appFileName);
MessageBox.Show(directory);
|
|
|
|
|
Quote: The System Volume Information folder is a hidden system folder that the System Restore tool uses to store its information and restore points. There is a System Volume Information folder on every partition on your computer.
Never store user data in the application folder. A normal user did not have write access when using the recommended Progam Files folder. Use one of the application data folders instead. Which one to use depends on roaming support and if shared access is required. See the AppData properties in the Application Class (System.Windows.Forms)[^] to get these pathes.
|
|
|
|
|
Thanks for the reply...
i don't want to use System Volume Information folder. But during enumeration process automatically the checking comes here, then generates an exception and terminates further execution. Is there any method to avoid these kind of system folders checking during enumeration?.
|
|
|
|
|
When you expect exceptions to be thrown catch them to avoid that the application terminates. In this case just ignore access denied exceptions and continue.
But there is no need to enumerate all directories when using a standard Windows folder for your application data.
|
|
|
|
|
|
thanks for the reply. . .
|
|
|
|
|
private static List<string> BadNames = new List<string>{"Adobe","CPMigrator","ServicePack","Symantec", "Server", "TumbleWeed"};
private static string targetFolder = "Common7";
static void Main(string[] args)
{
List<string> folders = GetFolders(@"C:\Program Files\");
string found = folders.FirstOrDefault(x=>x.ToUpper().EndsWith(targetFolder.ToUpper()));
}
public static List<string> GetFolders(string path)
{
List<string> folders = new List<string>();
foreach(string bad in BadNames)
{
if (path.ToUpper().Contains(bad.ToUpper()))
{
return folders;
}
}
try
{
folders = Directory.GetDirectories(path, "*.*", SearchOption.TopDirectoryOnly).ToList();
for (int i = 0; i <folders.Count; i++)
{
folders.AddRange(GetFolders(folders[i]));
}
}
catch (Exception)
{
}
return folders;
}
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
modified 13-Apr-18 9:41am.
|
|
|
|
|
Smallest window in a string containing all the characters of another string
|
|
|
|
|
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.
Try it yourself, you may find it is not as difficult as you think!
If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Looks a bit spammy to me.
|
|
|
|
|
The username does, but the message is clear of pink meat. And the user has been here for nearly two years.
I'll give it the benefit of the doubt for the moment - company names for your username are allowed.
Mind you, if he can't do that homework himself, I wouldn't use the company...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I am in the process of creating an intranet system for a local business. This system will contain a custom CRM, as well as various other components essential to the customers business.
They will shortly be switching their phone system to Skype.
We would like to develop a C# desktop app that talks with the skype application to detect when a phone call comes in, then flashes up various information for the user - such as customer name and account status.
Is there an API that will allow us to do this?
|
|
|
|
|
|
Except no-where on that page does it tell me how to integrate a C# application with skype. I don't want to create a bot, accept payments, conduct interviews or add call links to my web app.
I want to detect incoming calls on skype, and flash up additional data on the users screen.
And to clarify, I'm talking *desktop* application, not mobile.
modified 11-Apr-18 9:21am.
|
|
|
|
|
Sonetimes I think the better question is: How to turn Skype off ... cameras, mikes, status monitors, background zombies.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
I created an excel user defined function using excel dna Add-In, My function should return a two dimentional array but when i call it from a cell (=mainView(2018-04-10) ) it displays only the first column name (FundName), below is my code:
<pre> public static object[,] mainView(DateTime dt)
{
int rows = 0;
int columns = 0;
const int columnsArrayIndex = 0;
DataTable dt = new DataTable();
object[,] allRecords = new object[0,0];
try
{
SqlConnection cnx = new SqlConnection("data source=...;initial catalog=...;integrated security=True");
cnx.Open();
string query = @"select FundName,...";
SqlCommand cmd = new SqlCommand(query, cnx);
using (SqlDataAdapter a = new SqlDataAdapter(cmd))
{
a.Fill(dt);
rows = dt.Rows.Count;
columns = dt.Columns.Count;
if (columns > 0 && rows > 0)
{
allRecords = new object[rows + 1, columns];
for (int i = 0; i <= columns - 1; i++)
{
allRecords[columnsArrayIndex, i] = dt.Columns[i].ColumnName;
}
for (int j = 0; j <= rows - 1; j++)
{
var rowItem = dt.Rows[j].ItemArray;
for (int k = 0; k <= rowItem.Length - 1; k++)
{
allRecords[j + 1, k] = rowItem[k];
}
}
}
}
}
catch
{
}
return allRecords;
} I would like to get all the rows of the select query result displayed in the excel, the result of the select query is dynamic, it changes when the date changes. What is missing in my code please so that i can get the result i want ? how can i display all the rows and columns of my query in the excel ?
|
|
|
|
|
I would suggest getting rid of the empty Catch block. There could be exceptions occurring, but you have no idea what they are because you're ignoring them.
Once you know what exceptions are occurring, you can solve them.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|